title: CheckOut Cart MVC
body: <p>I am trying to create a checkout for the cart in my webshop project for classe.
  I want that every time that your press checkout it will take from the model Clothes.Amount 1 for each product that you have in the cart session.
  and then I want to clean the cart.</p>
  
  <p>In cart controller I have this three functions and one other to order but it is not important for this question i think.
  The error is int this lines </p>
  
  <pre><code>Item.Cl.Amount--;
  Delete(Item.Cl.Id);
  </code></pre>
  
  <p>Here is the code</p>
  
  <pre><code>private int isExisting(int id)
          {
              List&lt;Item&gt; cart = (List&lt;Item&gt;)Session["cart"];
              for (int i = 0; i &lt; cart.Count; i++)
              {
                  if (cart[i].Cl.Id == id)
                      return i;
              }return -1;
          }
  public ActionResult Delete(int idDelete)
          {
              int index = isExisting(idDelete);
              List&lt;Item&gt; cart = (List&lt;Item&gt;)Session["cart"];
              cart.RemoveAt(index);
              Session["cart"] = cart;
  
              return View("Order"); 
  
          }
  public ActionResult CheckOut(int idCheck)
          {
              int index = isExisting(idCheck);
              if(index != -1) { 
                  foreach (Item item in (List&lt;Item&gt;)Session["cart"]) {
                      Item.Cl.Amount--;
                      Delete(Item.Cl.Id);
                  }
              }
              return View();
          }
  </code></pre>