Ejemplo n.º 1
0
 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);
     }
 }
Ejemplo n.º 2
0
        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());
        }