public ActionResult Order(Customer customer, int Id = 1)
        {
            ProductStorage storage = new ProductStorage();
            if (!storage.ProductList.ContainsKey(Id))
            {
                return HttpNotFound();
            }

            if (ModelState.IsValid)
            {
                Order order = new Order()
                {
                    Customer = customer,
                    Date = DateTime.Now,
                    Product = storage.ProductList[Id]
                };

                OrderSender.SendNotifications(order);
                return View("Done");
            }


            ViewBag.SelectedProduct = storage.ProductList[Id];
            return View("Index");
        }
 private static string GetMessageForCustomer(Order order)
 {
     StringBuilder message = new StringBuilder();
     message.AppendLine($"Hello, {order.Customer.FirstName}!");
     message.AppendLine("Your ordered:");
     message.AppendLine();
     message.AppendLine(order.Date.ToShortDateString());
     message.AppendLine($"Product: {order.Product.Title}");
     message.AppendLine($"Cost: ${order.Product.Cost}");
     message.AppendLine("Thank you for your order!");
     return message.ToString();
 }
        public static void SendNotifications(Order order)
        {
            Sender EmailSender = new Sender
                (
                    host: "smtp.gmail.com",
                    port: 587,
                    enableSsl: true,
                    deliveryMethod: SmtpDeliveryMethod.Network,
                    useDefaultCredentials: false,
                    credentials: new NetworkCredential("*****@*****.**", "aspnetbu")
                );

            SendNotificationToCustomer(order, EmailSender);
            SendNotificationToShop(order, EmailSender);
        }
 private static string GetMessageForShop(Order order)
 {
     StringBuilder message = new StringBuilder();
     message.AppendLine("Customer info:");
     message.AppendLine($"First name: {order.Customer.FirstName}");
     message.AppendLine($"Last name: {order.Customer.LastName}");
     message.AppendLine($"Email: {order.Customer.Email}");
     message.AppendLine($"Phone: {order.Customer.Phone}");
     message.AppendLine($"Shipping address: {order.Customer.ShippingAddress}");
     message.AppendLine();
     message.AppendLine("Purchase:");
     message.AppendLine($"Name: <b>{order.Product.Title}</b>");
     message.AppendLine($"Cost: ${order.Product.Cost}");
     message.AppendLine($"Date: {order.Date}");
     return message.ToString();
 }
        public static bool SendNotificationToShop(Order order, Sender EmailSender)
        {
            string subject = $"New order {Convert.ToString(order.Date)}!";
            string body = GetMessageForShop(order);
            string toAddress = "*****@*****.**";

            try
            {
                EmailSender.SendMail(subject, body, toAddress);
                return true;
            }
            catch
            {
                return false;
            }

        }
        public static bool SendNotificationToCustomer(Order order, Sender EmailSender)
        {
            string subject = "MasterShop — New order";
            string body = GetMessageForCustomer(order);
            string toAddress = order.Customer.Email;

            try
            {
                EmailSender.SendMail(subject, body, toAddress);
                return true;
            }
            catch
            {
                return false;
            }
            
        }