// GET: Product/Edit/5 public ActionResult Edit(int id) { Product product = services.GetProdectById(id); ViewBag.categories = services.GetCategories(); return(View(product)); }
public ActionResult AddToCart(int ID) { if (Session["cart"] == null) { var cart = new List <Item>(); var product = services.GetProdectById(ID);//context.products.Find(prodid); if (product.Quantity > 1) { cart.Add(new Item() { Product = product, Quantity = 1 }); Session["cart"] = cart; } } else { List <Item> cart = (List <Item>)Session["cart"]; var product = services.GetProdectById(ID);//context.products.Find(prodid); var c = cart.Find(s => s.Product.ID == ID); if (c != null) { int prev = c.Quantity; cart.Remove(c); if (product.Quantity > 1) { cart.Add(new Item() { Product = product, Quantity = prev + 1 }); } } else { if (product.Quantity > 1) { cart.Add(new Item() { Product = product, Quantity = 1 }); Session["cart"] = cart; } } } return(RedirectToAction("Index", "Home")); }