Пример #1
0
 public void ProcessOrder(Cart cart, ShopinngDetalis shopinngDetalis)
 {
     using (SmtpClient 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 (emailSettings.WriteAsFile)
         {
             smtpClient.DeliveryMethod          = SmtpDeliveryMethod.SpecifiedPickupDirectory;
             smtpClient.PickupDirectoryLocation = emailSettings.FileLocation;
             smtpClient.EnableSsl = false;
         }
         StringBuilder body = new StringBuilder()
                              .AppendLine("A new order has been submitted")
                              .AppendLine("---")
                              .AppendLine("Items:");
         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);
         }
         body.AppendFormat("Total order value: {0:c}", cart.ComputeTotalValue())
         .AppendLine("---")
         .AppendLine("Ship to:")
         .AppendLine(shopinngDetalis.Name)
         .AppendLine(shopinngDetalis.Line1)
         .AppendLine(shopinngDetalis.Line2 ?? "")
         .AppendLine(shopinngDetalis.Line3 ?? "")
         .AppendLine(shopinngDetalis.City)
         .AppendLine(shopinngDetalis.State ?? "")
         .AppendLine(shopinngDetalis.Country)
         .AppendLine(shopinngDetalis.Zip)
         .AppendLine("---")
         .AppendFormat("Gift wrap: {0}", shopinngDetalis.GiftWrap ? "Yes" : "No");
         MailMessage mailMessage = new MailMessage(
             emailSettings.MailFromAddress, // From
             emailSettings.MailToAddress,   // To
             "New order submitted!",        // Subject
             body.ToString());              // Body
         if (emailSettings.WriteAsFile)
         {
             mailMessage.BodyEncoding = Encoding.ASCII;
         }
         smtpClient.Send(mailMessage);
     }
 }
Пример #2
0
 public ViewResult Checkout(Cart c, ShopinngDetalis shopinngDetalis)
 {
     if (c.Lines.Count() == 0)
     {
         ModelState.AddModelError("", "Sorri,your cart is Empty!!");
     }
     if (ModelState.IsValid)
     {
         orderProcerssor.ProcessOrder(c, shopinngDetalis);
         c.Clear();
         return(View("Complated"));
     }
     else
     {
         return(View(shopinngDetalis));
     }
 }