예제 #1
0
 private void GenerateSampleData()
 {
     using (var session = DocumentStoreHolder.DocumentStore.OpenSession())
     {
         for (int i = 0; i < 15; i++)
         {
             var order = new Order()
                             {
                                 Customer = new Customer()
                                                {
                                                    FullName = "Name of Customer " + i.ToString(),
                                                    Category = new Category()
                                                                   {
                                                                       Description = "Category " + i.ToString(),
                                                                       DiscountPercent = Convert.ToDecimal(i)
                                                                   },
                                                    Email = "*****@*****.**"
                                                },
                                 OrderItems = new List<OrderItem>()
                                                  {
                                                      new OrderItem() {Product = new Product(){ProductName = "Product Name "+i.ToString(),ProductCode = "Code",UnitPrice = Convert.ToDecimal(i)},Acknowledged = false,Confirmed = true,Quantity = Convert.ToDecimal(i)},
                                                      new OrderItem() {Product = new Product(){ProductName = "Product Name "+i.ToString(),ProductCode = "Code",UnitPrice = Convert.ToDecimal(i)},Acknowledged = true,Confirmed = true,Quantity = Convert.ToDecimal(i)},
                                                      new OrderItem() {Product = new Product(){ProductName = "Product Name "+i.ToString(),ProductCode = "Code",UnitPrice = Convert.ToDecimal(i)},Acknowledged = false,Confirmed = false,Quantity = Convert.ToDecimal(i)}
                                                  },
                                 DateOrdered = DateTime.Now
                             };
             session.Store(order);
         }
         session.SaveChanges();
     }
 }
예제 #2
0
 public ActionResult Confirmation(int id)
 {
     var order = new Order();
     using(var session=DocumentStoreHolder.DocumentStore.OpenSession())
     {
         order = session.Load<Order>(id);
         foreach (var orderItem in order.OrderItems)
         {
             orderItem.Confirmed = true;
         }
         session.SaveChanges();
     }
     return View();
 }
예제 #3
0
 public ActionResult OrderReceived(Order order)
 {
     using (var session = DocumentStoreHolder.DocumentStore.OpenSession())
     {
         session.Store(order);
         session.SaveChanges();
         foreach (var orderItem in order.OrderItems)
         {
             orderItem.Acknowledged = true;
         }
         session.SaveChanges();
         ViewData["Message"] =
             "Your licences will be sent to the email address provided. We thank you.";
         CommandExecuter.ExcuteLater(new SendEmailCommand(order));
     }
     return View();
 }
예제 #4
0
        //Read SMTP configuration from web.config
        //should be with attachment
        public static bool SendEMail(Order order)
        {
            var customerServiceEmail = ConfigurationManager.AppSettings["ReturnAddress"];
            foreach (var orderItem in order.OrderItems)
            {
                string message = "Dear " + order.Customer.FullName + "\n" + //Construct the appropriate message here
                                 "Attached is your licence for the product " + orderItem.Product.ProductName;
                //This is gives the user to confirm the receipt of the licence file
                message += "Please click the following link to confirm receipt of the licence http://localhost:/Order/Confirmation/";

                string subject = "Licence from Hibernating Rhino";
                var mailMessage = new MailMessage()
                                      {
                                          IsBodyHtml = true,
                                          Body = message,
                                          Subject = subject
                                      };
                mailMessage.To.Add(new MailAddress(order.Customer.Email));

                if(customerServiceEmail!=null)
                    mailMessage.ReplyToList.Add(new MailAddress(customerServiceEmail));

                try
                {
                    var attachment = new Attachment("http://localhost/Licence/Create");//the path to the generated licence file goes here.
                    mailMessage.Attachments.Add(attachment);
                    using (var smtpClient = new SmtpClient())
                    {
                        smtpClient.Send(mailMessage);
                    }
                }
                catch
                {
                    return false;
                }
            }
            return true;
        }
예제 #5
0
 public SendEmailCommand(Order order)
 {
     _order = order;
 }