public ActionResult Cart(int itemId) { bool itemFound = false; MenuDomainModel menu = new MenuDomainModel(); ItemModel item = menu.GetItem(itemId); ViewBag.Message = "You have added " + item.ItemName; cartModel = (CartModel)Session["CartModel"]; if (cartModel == null) { cartModel = new CartModel { SelectedItems = new List <ItemModel>() } } ; foreach (ItemModel modelItem in cartModel.SelectedItems.ToList()) { if (itemId == modelItem.ItemId) { var toUpdate = cartModel.SelectedItems.FirstOrDefault(s => s.ItemId == itemId); toUpdate.AddQuantity(Convert.ToInt32(modelItem.Quantity) + 1); itemFound = true; break; } } if (!itemFound) { cartModel.SelectedItems.Add(item); } Session["CartModel"] = cartModel; return(View("Cart", cartModel)); }
public ActionResult Index() { MenuDomainModel menu = new MenuDomainModel(); MenuModel model; model = menu.GetItems(); return(View(model)); }