public ActionResult ViewProductDetail(int id) { var Model = new ProductDetailViewModel { Product = ShoppingCartCSV.GetProduct(id) }; return(View(Model)); }
public ActionResult AddToCart(ProductDetailViewModel ProductDetailViewModel) { if (ProductDetailViewModel.Quantity < 1) { return(RedirectToAction("ViewCart")); } else { var product = ShoppingCartCSV.GetProduct(ProductDetailViewModel.Product.Id); var quantity = ProductDetailViewModel.Quantity; Item item = new Item { Product = product, Quantity = quantity }; this.SetSession("Cart"); var v = cart.Items.FirstOrDefault(x => x.Product.Id.Equals(product.Id)); if (v == null) { cart.Items.Add(item); } else { v.Quantity += quantity; } Session.Add("Cart", cart); return(RedirectToAction("ViewCart")); } }