コード例 #1
0
        public void SendOrderConfirmation(Order order)
        {
            var body = "Thank you, we have received your order for " + order.Quantity + " unit(s) of " + order.Product.Name + "!<br />";
            var orderShipping = order.ShippingAddress;
            var customerEmail = order.EmailAddress;

            // Replace carriage returns with HTML breaks for HTML mail
            var formattedOrder = orderShipping.Replace("\r\n", "<br />");
            body += "Your address is: <br />" + formattedOrder + "<br />";

            body += "Your total is $" + (order.Product.Price * order.Product.Price) + ".<br />";
            body += "We will contact you if we have questions about your order. Thanks!<br />";

            try
            {
                //SMTP Configuration for HOTMAIL
                WebMail.SmtpServer = "smtp.live.com";
                WebMail.SmtpPort = 25;
                WebMail.EnableSsl = true;

                //Enter your hotmail credentails for UserName/Password and a "From" address for the e-mail
                WebMail.UserName = "";
                WebMail.Password = "";
                WebMail.From = "";
                WebMail.Send(to: customerEmail, subject: "Fourth Coffee - New Order", body: body);
            }
            catch (Exception)
            {
                // only placed here to allow app to run without configuring email
            }
        }
コード例 #2
0
 public ActionResult Index(OrderFormModel model)
 {
     if (ModelState.IsValid)
     {
         Order order = new Order
         {
             Product = model.Product,
             ShippingAddress = model.OrderShipping,
             EmailAddress = model.OrderEmail,
             Quantity = model.OrderQty
         };
         IOrderService service = new OrderService();
         service.ProcessOrder(order);
         return View("Success");
     }
     else
     {
         if (model.Product.Id > 0)
         {
             IProductService service = new ProductService();
             model = new OrderFormModel
             {
                 Product = service.GetProduct(model.Product.Id)
             };
             return View(model);
         }
         else
         {
             return RedirectToRoute("Default");
         }
     }
 }
コード例 #3
0
 public void ProcessOrder(Order order)
 {
     IMailService service = new MailService();
     service.SendOrderConfirmation(order);
 }