public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { Cart cart = (Cart)controllerContext.HttpContext.Session[sessionKey]; if (cart == null) { cart = new Cart(); controllerContext.HttpContext.Session[sessionKey] = cart; } return cart; }
public RedirectToRouteResult RemoveFromCart(Cart cart, int productID, string returnUrl) { Products product = repository.Products.FindById(productID); if (product == null) throw new HttpException(404, "Not found"); if (product != null) { cart.RemoveLine(product); } return RedirectToAction("Index", new { returnUrl }); }
public RedirectToRouteResult AddToCart(Cart cart, int productID, string returnUrl, int quantity = 1) { Products product = repository.Products.FindById(productID); if(product==null) throw new HttpException(404, "Not found"); if (product != null) { cart.AddItem(product, quantity); } return RedirectToAction("Index", new { returnUrl }); }
public ViewResult Summary(Cart cart) { return View(cart); }
public ViewResult Index(Cart cart, string returnUrl) { return View(new CartIndexViewModel { Cart = cart, ReturnUrl = returnUrl }); }