public ActionResult UpdateStoreQuantity() { Cart cart = (Cart) Session["cart"]; foreach(ProductStock cartProductStock in cart.CustomerPurchaseItems) { // Look up the actual product stock from the database. ProductStock productStock = db.ProductStocks.Find(cartProductStock.ProductID, cartProductStock.StoreID); // Change the quantity in the database. productStock.Quantity -= cartProductStock.Quantity; } // Update database db.SaveChanges(); // Reset cart. Session["cart"] = new Cart(); return RedirectToAction("Index"); }
protected void Session_Start() { Session["cart"] = new Cart(); }