public ActionResult MiniShoppingCartSingleItem(int id) { DishesBuss buss = new DishesBuss(); var dishInfo = buss.GetSingleDishes(id); return(View(dishInfo)); }
private List <ShoppingCartItem> OperateShoppingCart(int id, int qty) { DishesBuss buss = new DishesBuss(); List <ShoppingCartItem> shoppingCartItems = null; var jser = new JavaScriptSerializer(); if (Request.Cookies["shoppingCart"] != null) { var cookieJson = Request.Cookies["shoppingCart"].Value; shoppingCartItems = jser.Deserialize <List <ShoppingCartItem> >(cookieJson); } if (shoppingCartItems == null || shoppingCartItems.Count == 0) { shoppingCartItems = new List <ShoppingCartItem>(); } var isContaint = false; var index = 0; foreach (var item in shoppingCartItems) { if (item.ItemID == id && qty > 0) { item.Qty = qty; isContaint = true; break; } if (item.ItemID == id && qty == 0) { isContaint = true; break; } index++; } if (qty == 0) { shoppingCartItems.RemoveAt(index); } if (isContaint == false) { var dishInfo = buss.GetSingleDishes(id); ShoppingCartItem cartitem = new ShoppingCartItem(); cartitem.ItemID = id; cartitem.Qty = qty; cartitem.EName = dishInfo.EName; //cartitem.OName = dishInfo.OtherName; cartitem.Price = dishInfo.Price; shoppingCartItems.Add(cartitem); } var json = jser.Serialize(shoppingCartItems); Response.Cookies["shoppingCart"].Value = json; Response.Cookies["shoppingCart"].Expires = DateTime.Now.AddHours(1); return(shoppingCartItems); }