// GET: Cart public ActionResult Index(string id) { vegetableModel vegetableModel = new vegetableModel(); ViewBag.vegetables = vegetableModel.findAll(); return(View()); }
public ActionResult Buy(string id) { vegetableModel vegetableModel = new vegetableModel(); if (Session["cart"] == null) { List <Item> cart = new List <Item>(); cart.Add(new Item { Vegetable = vegetableModel.find(id), Quantity = 1 }); Session["cart"] = cart; } else { List <Item> cart = (List <Item>)Session["cart"]; int index = isExist(id); if (index != -1) { cart[index].Quantity++; } else { cart.Add(new Item { Vegetable = vegetableModel.find(id), Quantity = 1 }); } Session["cart"] = cart; } return(RedirectToAction("Index")); }
// GET: Vegetable public ActionResult Vegetable() { vegetableModel vegetableModel = new vegetableModel(); ViewBag.vegetables = vegetableModel.findAll(); return(View()); }