//Get public ViewResult Index(Cart cart, string returnUrl) { return View (new CartIndexViewModel{ //Cart = GetCart(), ReturnUrl = returnUrl, Cart = cart }); }
public void ProcessOrder(Cart cart, ShippingDetails shippingInfo) { using (var smtpClient = new SmtpClient()) { smtpClient.EnableSsl = emailSettings.UseSsl; smtpClient.Host = emailSettings.ServerName; smtpClient.Port = emailSettings.ServerPort; smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = new NetworkCredential(emailSettings.UserName, emailSettings.Password); //If the order is flagged to write to a file, set file location information. if (emailSettings.WriteAsFile) { smtpClient.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory; smtpClient.PickupDirectoryLocation = emailSettings.FileLocation; smtpClient.EnableSsl = false; } //Start of the Order Proccessing email/file StringBuilder body = new StringBuilder() .Append("A new order has been submitted") .AppendLine("---") .AppendLine("Items:"); //for each set of items show to quanity, name, and subtotal cost. //and add it to the email/file body foreach (var line in cart.Lines) { var subtotal = line.Product.Price * line.Quantity; body.AppendFormat("{0} x {1} (subtotal: {2:c}", line.Quantity, line.Product.Name, subtotal); } //Adds total order information, plus shipping details to email/file body body.AppendFormat("Total order value: {0:c}", cart.ComputeTotalValue()) .AppendLine("---") .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("---") .AppendFormat("Gift wrap: {0}", shippingInfo.GiftWrap ? "Yes" : "No"); //Creates a new mail message. MailMessage mailMessage = new MailMessage(emailSettings.MailFromAddress, emailSettings.MailToAddress, "New Order Submitted!", body.ToString()); if (emailSettings.WriteAsFile) { mailMessage.BodyEncoding = Encoding.ASCII; } smtpClient.Send(mailMessage); } }
public RedirectToRouteResult AddToCart(Cart cart, int productID, string returnUrl) { //Finds the product by the product id. Product product = repository.Products.FirstOrDefault(p => p.ProductID == productID); //Integrity check. If the item exists then add one to the cart, otherwise do nothing. if (product != null) { //GetCart().AddItem(product, 1); cart.AddItem(product, 1); } //Send user to the shopping cart with a return url of where they were when they //clicked the "Add to cart" button. return RedirectToAction("Index", new { returnUrl }); }
public ViewResult Checkout(Cart cart, ShippingDetails shippingDetails) { //If there is nothing in the cart, do not let them checkout. if (cart.Lines.Count() == 0) { ModelState.AddModelError("", "Sorry, your cart is empty!"); } if (ModelState.IsValid) { orderProcessor.ProcessOrder(cart, shippingDetails); cart.Clear(); return View("Completed"); } else { return View(shippingDetails); } }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { //Get the Cart from Session state Cart cart = null; if (controllerContext.HttpContext.Session != null) { cart = (Cart)controllerContext.HttpContext.Session[sessionKey]; } //Create the Cart if there wasn't one in session data if (cart == null) { cart = new Cart(); if (controllerContext.HttpContext.Session != null) { controllerContext.HttpContext.Session[sessionKey] = cart; } } return cart; }
public RedirectToRouteResult RemoveFromCart(Cart cart, int productID, string returnUrl) { //Finds the product by the product id. Product product = repository.Products.FirstOrDefault(p => p.ProductID == productID); //Integrity check. If the item exists the remove, otherwise do nothing. if (product != null) { //GetCart().RemoveLine(product); cart.RemoveLine(product); } //Sends user to the shopping cart page with a return url of where they were when they //clicked the "remove from cart" button. return RedirectToAction("Index", new { returnUrl }); }
public PartialViewResult Summary(Cart cart) { return PartialView(cart); }