Example #1
0
 public RedirectToRouteResult AddToCart(Cart cart, int productId,
 string returnUrl)
 {
     Product product = repository.Products
     .FirstOrDefault(p => p.ProductID == productId);
     if (product != null)
     {
         cart.AddItem(product, 1);
     }
     return RedirectToAction("Index", new { returnUrl });
 }
Example #2
0
 public RedirectToRouteResult UpdateCart(Cart cart, int productId, string returnUrl, int quantity)
 {
     Product product = repository.Products
         .FirstOrDefault(p => p.ProductID == productId);
     int q = cart.Lines.FirstOrDefault(p => p.Product.ProductID == productId).Quantity;
     if (product != null && q+quantity>0)
     {
         cart.AddItem(product, quantity);
     }
     return RedirectToAction("Index", new { returnUrl });
 }