public ViewResult Index(Cart cart, string returnUrl) { return View(new CartIndexViewModel { Cart = cart, ReturnUrl = returnUrl }); }
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) { // get the Cart from the session Cart cart = (Cart)controllerContext.HttpContext.Session[sessionKey]; // create the Cart if there wasn't one in the session data if (cart == null) { cart = new Cart(); controllerContext.HttpContext.Session[sessionKey] = cart; } // return the cart return cart; }
public ViewResult Checkout(Cart cart, ShippingDetails shippingDetails) { if (cart.Lines.Count() == 0) { ModelState.AddModelError("", "Sorry, your cart is empty!"); } if (ModelState.IsValid) { orderProcessor.ProcessOrder(cart, shippingDetails); cart.Clear(); return View("Completed", shippingDetails); //return View("Payment"); } else { return View(shippingDetails); } }
public void ProcessOrder(Cart cart, ShippingDetails shippingInfo) { WebMail.SmtpServer = "smtp.gmail.com"; WebMail.SmtpPort = 587; WebMail.EnableSsl = true; WebMail.UserName = "******"; WebMail.Password = "******"; WebMail.From = "*****@*****.**"; StringBuilder body = new StringBuilder() .AppendLine("A new order has been submitted from DienChan:") .AppendLine("<br/>") .AppendLine("Items:"); foreach (var line in cart.Lines) { body.AppendLine("<br/>"); var subtotal = line.Product.Price * line.Quantity; body.AppendFormat("{0} x {1} (subtotal: {2:c})", line.Quantity, line.Product.Name, subtotal); } body.AppendLine("<br/>"); body.AppendFormat("Total order value: {0:c}", cart.ComputeTotalValue()) .AppendLine("<br/>") .AppendLine("Ship to:") .AppendLine(shippingInfo.Name) .AppendLine(shippingInfo.Line1) .AppendLine(shippingInfo.Line2 ?? "") .AppendLine(shippingInfo.Line3 ?? "") .AppendLine(shippingInfo.City) .AppendLine(shippingInfo.State ?? "") .AppendLine(shippingInfo.Country) .AppendLine(shippingInfo.Zip) .AppendLine("<br/>") .AppendFormat("Gift wrap: {0}", shippingInfo.GiftWrap ? "Yes" : "No"); WebMail.Send(shippingInfo.Email, "New order submitted!", body.ToString()); WebMail.Send(shippingInfo.Email, "New order submitted!", body.ToString()); }
public PartialViewResult Summary(Cart cart) { return PartialView(cart); }
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 }); }