Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPost]
- public ActionResult SelectProduct(BrandViewModel vm)
- {
- Dictionary<int, object> cart;
- if (HttpContext.Session.Get<Dictionary<int, object>>("cart") == null)
- {
- cart = new Dictionary<int, object>();
- }
- else
- {
- cart = HttpContext.Session.Get<Dictionary<int, object>>("cart");
- }
- ProductViewModel[] menu = HttpContext.Session.Get<ProductViewModel[]>("menu");
- String retMsg = "";
- foreach (ProductViewModel item in menu)
- {
- if (Convert.ToInt32(item.Id) == vm.Id)
- {
- if (vm.Qty > 0) // update only selected item
- {
- item.Qty = vm.Qty;
- retMsg = vm.Qty + " - item(s) Added!";
- cart[Convert.ToInt32(item.Id)] = item;
- }
- else
- {
- item.Qty = 0;
- cart.Remove(Convert.ToInt32(item.Id));
- retMsg = "item(s) Removed!";
- }
- vm.BrandId = item.BrandId;
- break;
- }
- }
- ViewBag.AddMessage = retMsg;
- HttpContext.Session.Set<Dictionary<int, object>>("cart", cart);
- vm.SetBrands(HttpContext.Session.Get<List<Brand>>("brands"));
- return View("Index", vm);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement