public void ProcessOrder(Cart cart, ShopingDetails shopingDetails)
        {
            using (var smtpClient = new SmtpClient())
            {
                smtpClient.EnableSsl             = emailSetting.UseSsl;
                smtpClient.Host                  = emailSetting.ServerName;
                smtpClient.Port                  = emailSetting.ServerPort;
                smtpClient.UseDefaultCredentials = false;
                smtpClient.Credentials           = new NetworkCredential(emailSetting.Username, emailSetting.Password);

                if (emailSetting.WriteAsFile)
                {
                    smtpClient.DeliveryMethod          = SmtpDeliveryMethod.SpecifiedPickupDirectory;
                    smtpClient.PickupDirectoryLocation = emailSetting.FileLocation;
                    smtpClient.EnableSsl = false;
                }

                StringBuilder body = new StringBuilder()
                                     .AppendLine("Новый заказ обработан")
                                     .AppendLine("----")
                                     .AppendLine("Товары:");

                foreach (var line in cart.Lines)
                {
                    var subtotal = line.book.Price * line.Quantity;
                    body.AppendFormat("{0} x {1} (Итого: {2:c})", line.Quantity, line.book.Name, subtotal);
                }

                body.AppendFormat("Общая стоймость: {0:c}", cart.ComputeTotalValue())
                .AppendLine("------")
                .AppendLine("Доставка:")
                .AppendLine(shopingDetails.Name)
                .AppendLine(shopingDetails.line1)
                .AppendLine(shopingDetails.line2 ?? "")
                .AppendLine(shopingDetails.line3 ?? "")
                .AppendLine(shopingDetails.City)
                .AppendLine(shopingDetails.Country)
                .AppendLine("------")
                .AppendFormat("Подарочная упоковка: {0}", shopingDetails.WrapGift ? "Да" : "Нет");

                MailMessage mailMessage = new MailMessage(
                    emailSetting.MailFromAddress,
                    emailSetting.MailToAddress,
                    "Новый заказ отправлен!",
                    body.ToString()
                    );

                if (emailSetting.WriteAsFile)
                {
                    mailMessage.BodyEncoding = Encoding.UTF8;
                }

                smtpClient.Send(mailMessage);
            }
        }
Ejemplo n.º 2
0
        public void ProcessOrder(Cart cart, ShopingDetails shopDetails)
        {
            using (var smtpClient = new SmtpClient())
            {
                smtpClient.EnableSsl             = mailSttings.UseSsl;
                smtpClient.Host                  = mailSttings.ServerName;
                smtpClient.Port                  = mailSttings.ServerPort;
                smtpClient.UseDefaultCredentials = false;
                smtpClient.Credentials           = new NetworkCredential(mailSttings.Username, mailSttings.Password);
                if (mailSttings.WriteAsFile)
                {
                    smtpClient.DeliveryMethod          = SmtpDeliveryMethod.SpecifiedPickupDirectory;
                    smtpClient.PickupDirectoryLocation = mailSttings.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(shopDetails.Name)
                .AppendLine(shopDetails.line1)
                .AppendLine(shopDetails.line2 ?? "")
                .AppendLine(shopDetails.line3 ?? "")
                .AppendLine(shopDetails.City)
                .AppendLine(shopDetails.State ?? "")
                .AppendLine(shopDetails.Zip)
                .AppendLine("---")
                .AppendFormat("Gift wrap: {0}", shopDetails.GiftWrap ? "Yes" : "No");

                MailMessage mailMessage = new MailMessage(
                    mailSttings.MailFromAddress,
                    mailSttings.MailToAddress,
                    "new order submitted!",
                    body.ToString()
                    );
                if (mailSttings.WriteAsFile)
                {
                    mailMessage.BodyEncoding = Encoding.ASCII;
                }
                smtpClient.Send(mailMessage);
            }
        }
Ejemplo n.º 3
0
        public void Cannot_Checkout_Empty_Cart()
        {
            Mock <IOrderProcessor> mock   = new Mock <IOrderProcessor>();
            Cart           cart           = new Cart();
            ShopingDetails shopingDetails = new ShopingDetails();

            CartController controller = new CartController(null, mock.Object);

            ViewResult result = controller.CheckOut(cart, shopingDetails);

            //????
            mock.Verify(m => m.ProcessOrder(It.IsAny <Cart>(), It.IsAny <ShopingDetails>()), Times.Never());

            Assert.AreEqual("", result.ViewName);
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
Ejemplo n.º 4
0
        public ViewResult CheckOut(Cart cart, ShopingDetails shopingDetails)
        {
            if (cart.Lines.Count() == 0)
            {
                ModelState.AddModelError("", "Извините, корзина пуста!");
            }

            if (ModelState.IsValid)
            {
                orderProcessor.ProcessOrder(cart, shopingDetails);
                cart.Clear();
                return(View("Complited"));
            }
            else
            {
                return(View(new ShopingDetails()));
            }
        }
Ejemplo n.º 5
0
        public ViewResult Checkout(Cart cart, ShopingDetails shopDetails)
        {
            if (cart.Lines.Count() == 0)
            {
                ModelState.AddModelError("", "Sorry, your cart is empty");
            }
            if (ModelState.IsValid)
            {
                orderProcessor.ProcessOrder(cart, shopDetails);
                cart.Clear();
                return(View("Completed"));
            }

            else
            {
                return(View(shopDetails));
            }
        }
Ejemplo n.º 6
0
        public ViewResult Checkout(Cart cart, ShopingDetails shopingDetails)
        {
            if (cart.Lines.Count() == 0)
            {
                ModelState.AddModelError("", "Корзина пуста!");
            }

            if (ModelState.IsValid)
            {
                detailsRepository.AddShopingDetails(shopingDetails);

                cart.Clear();
                return(View("Completed"));
            }
            else
            {
                return(View(new ShopingDetails()));
            }
        }
 public void AddShopingDetails(ShopingDetails details)
 {
     context.ShopingDetails.Add(details);
     context.SaveChanges();
 }