public RedirectToRouteResult RemoveFromCart(Cart cart,int productId,string returnUrl) { Product product = repository.Products.FirstOrDefault(p => p.ProductId == productId); if (product != null) { cart.RemoveLine(product); } return RedirectToAction("Index", new { returnUrl }); }
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 }); }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { Cart cart = null; if (controllerContext.HttpContext.Session != null) { cart = (Cart)controllerContext.HttpContext.Session[sessionKey]; } if (cart == null) { cart = new Cart(); if (controllerContext.HttpContext.Session != null) controllerContext.HttpContext.Session[sessionKey] = cart; } return cart; }
public PartialViewResult Summary(Cart cart) { return PartialView(cart); }
public ViewResult Index(Cart cart,string returnUrl) { return View(new CartIndexViewModel { Cart = cart, ReturnUrl = returnUrl }); }