// GET: Shop public ActionResult AddTooCart(Guid id) { List <ShopCartItem> _list = new List <ShopCartItem>(); if (Session["ShopCart"] != null) { _list = Session["ShopCart"] as List <ShopCartItem>; } var product = db.Products.Find(id); if (_list.Any(p => p.ProductID == id)) { int index = _list.FindIndex(p => p.ProductID == id); if (WareHouseChecker.Count(id) > _list[index].Count) { _list[index].Count += 1; } } else { _list.Add(new ShopCartItem() { Count = 1, Title = product.Title, ProductID = id }); } Session["ShopCart"] = _list; return(PartialView("ShowListShopCart", _list)); }
// GET: Admin/WareHouse public ActionResult Index() { List <WareHouseItem> list = new List <WareHouseItem>(); foreach (var productse in db.Products) { list.Add(new WareHouseItem() { ProductID = productse.ProductID, ProductTitle = productse.Title, Count = WareHouseChecker.Count(productse.ProductID) }); } return(View(list)); }
public ActionResult CommandShopCart(Guid id, int type) { List <ShopCartItem> _list = new List <ShopCartItem>(); if (Session["ShopCart"] != null) { _list = Session["ShopCart"] as List <ShopCartItem>; int index = _list.FindIndex(p => p.ProductID == id); switch (type) { case 1: { if (WareHouseChecker.Count(id) > _list[index].Count) { _list[index].Count += 1; } break; } case 2: { _list[index].Count -= 1; if (_list[index].Count == 0) { _list.RemoveAt(index); } break; } case 3: { _list.RemoveAt(index); break; } } } Session["ShopCart"] = _list; return(PartialView("ShowListShopCart", _list)); }