Ejemplo n.º 1
0
        public void ProcessOrder(Cart cart, ShippingDetails shippingDetails)
        {
            using (var smtp = new SmtpClient(ServerName))
            {
                smtp.Credentials = new NetworkCredential(Username, Password);
                smtp.Port = ServerPort;
                smtp.EnableSsl = UseSsl;

                MailMessage message = new MailMessage();
                message.From = new MailAddress(MailFromAddress);
                message.To.Add(new MailAddress(shippingDetails.Email));
                message.Subject = "Order from AutoDealer";
                message.Body = GetBody(cart, shippingDetails);
                message.BodyEncoding = Encoding.Unicode;

                try
                {
                    smtp.Send(message);
                }
                catch (SmtpException ex)
                {
                    //TODO
                }
            }
        }
Ejemplo n.º 2
0
        public ViewResult Checkout(Cart cart, ShippingDetails shippingDetails)
        {
            if (!cart.Lines.Any())
            {
                ModelState.AddModelError("", "Sorry, your cart is empty!");
            }
            if (ModelState.IsValid)
            {
                _orderProcessor.ProcessOrder(cart, shippingDetails);
                cart.Clear();
                return View("Completed");
            }

            return View(shippingDetails);
        }
Ejemplo n.º 3
0
        private string GetBody(Cart cart, ShippingDetails shippingDetails)
        {
            StringBuilder body = new StringBuilder();
            body.AppendFormat("Dear, {0}!" , shippingDetails.Name).AppendLine();

            body.AppendLine("Your order include next goods: ");
            foreach (var cartLine in cart.Lines)
            {
                body.AppendFormat("Name : {0}", cartLine.Name).AppendLine();
                body.AppendFormat("Quantity : {0}", cartLine.Quantity).AppendLine();
                body.AppendFormat("Cost : {0} ", cartLine.Cost).AppendLine();
                body.AppendLine("---");
            }

            body.AppendFormat("Total cost of your ordes is: {0}", cart.ComputeTotalValue()).AppendLine();

            body.AppendLine("Thanks for you order.");
            body.AppendLine("Best regards, AutoDealer.");
            return body.ToString();
        }