public ViewResult Index(Cart cart, string returnUrl)
 {
     return View(new CartIndexViewModel
     {
         Cart = cart,
         ReturnUrl = returnUrl
     });
 }
        public void RemoveLines_no_this_type_of_menu_items()
        {
            //Arrange
            var cart = new Cart();
            var testMenuItem = new MenuItem();

            //Act
            cart.RemoveLine(testMenuItem);
        }
 public RedirectToRouteResult RemoveFromCart(Cart cart, int menuItemId, string returnUrl)
 {
     var menuItem = _baseDataAccess.GetMenuItems()
     .FirstOrDefault(m => m.Id == menuItemId);
     if (menuItem != null)
     {
         cart.RemoveLine(menuItem);
     }
     return RedirectToAction("Index", new { returnUrl });
 }
        public ViewResult Checkout(Cart cart, OrderDetails orderDetails)
        {
            if (!ModelState.IsValid)
                return View(orderDetails);

            if (CheckCartContent(cart))
                if (!ProcessOrder(cart, orderDetails))
                    return View("Error");

            cart.Clear();
            return View("Completed");
        }
        public RedirectToRouteResult AddToCart(Cart cart, int id, string returnUrl)
        {
            var menuItem = _baseDataAccess.GetMenuItems()
            .FirstOrDefault(m => m.Id == id);

            if (menuItem == null)
                throw new ArgumentException("There is no item with this id");

            cart.AddItem(menuItem, 1);

            return RedirectToAction("Index", new { returnUrl });
        }
        public object BindModel(ControllerContext controllerContext,
        ModelBindingContext bindingContext)
        {
            var cart = (Cart)controllerContext.HttpContext.Session[sessionKey];

            if (cart != null) return cart;

            cart = new Cart();
            controllerContext.HttpContext.Session[sessionKey] = cart;
            // return the cart
            return cart;
        }
        public bool Execute(Cart cart, OrderDetails orderDetails)
        {
            var fromAddress = new MailAddress("*****@*****.**", "From Bar");
            var toAddress = new MailAddress("*****@*****.**", "To Me");
            const string fromPassword = "******";
            const string subject = "New Order";
            var body = new StringBuilder()
                .AppendLine(string.Format("New Order from {0}", orderDetails.Name))
                .AppendLine(string.Format("Number {0}", orderDetails.Number))
                .AppendLine(string.Format("On {0}", orderDetails.Date))
                .AppendLine();

            foreach (var line in cart.Lines)
            {
                var subtotal = line.MenuItem.Price.Amount * line.Quantity;
                body.AppendLine(string.Format("{0} x {1} (subtotal: {2:c}", line.Quantity,
                line.MenuItem.Name,
                subtotal));
            }

            body.AppendLine()
                .AppendLine(string.Format("Total order value: {0:c}", cart.ComputeTotalValue()));

            var smtp = new SmtpClient
            {
                Host = "smtp.gmail.com",
                Port = 587,
                EnableSsl = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
            };
            using (var message = new MailMessage(fromAddress, toAddress)
            {
                Subject = subject,
                Body = body.ToString()
            })
            {
                smtp.Send(message);
            }

            return true;
        }
 private void InitializeEmptyCart()
 {
     _cart = new Cart();
     _menuItemsInCart = _cart.Lines;
 }
        private bool CheckCartContent(Cart cart)
        {
            if (cart.Lines.Any()) return true;

            ModelState.AddModelError("", ApplicationResources.EmptyOrderMessage);
            return false;
        }
示例#10
0
 public PartialViewResult Summary(Cart cart)
 {
     return PartialView(cart);
 }
示例#11
0
        private bool ProcessOrder(Cart cart, OrderDetails orderDetails)
        {
            orderDetails.ClientId = _authProvider.GetClientId();

            if (_orderProcessorCommand.Execute(cart, orderDetails)) return true;

            ModelState.AddModelError("", ApplicationResources.ProcessingErrorMessage);
            return false;
        }