Пример #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
                }
            }
        }
Пример #2
0
 public ViewResult Index(Cart cart, string returnUrl)
 {
     return View(new CartIndexViewModel
     {
         Cart = cart,
         ReturnUrl = returnUrl
     });
 }
Пример #3
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            Cart cart = (Cart)controllerContext.HttpContext.Session[_sessionKey];

            if (cart == null)
            {
                cart = new Cart();
                controllerContext.HttpContext.Session[_sessionKey] = cart;
            }

            // return the cart
            return cart;
        }
Пример #4
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);
        }
Пример #5
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();
        }
Пример #6
0
 public PartialViewResult Summary(Cart cart)
 {
     return PartialView(cart);
 }
Пример #7
0
        public RedirectToRouteResult RemoveFromCart(Cart cart, string productId, string returnUrl)
        {
            cart.RemoveLine(productId);

            return RedirectToAction("Index", new { returnUrl });
        }
Пример #8
0
        public RedirectToRouteResult AddToCart(Cart cart, string productId, string productType, string name, decimal cost, string returnUrl)
        {
            cart.AddItem(productId, productType, name, cost, 1);

            return RedirectToAction("Index", new { returnUrl });
        }