Пример #1
0
        public ActionResult CheckOut(
            [ModelBinder(typeof(ShoppingCartBinder))] ShoppingCart shoppingCart)
        {
            Order order = new Order
            {
                OrderID   = Guid.NewGuid().ToString(),
                OrderTime = DateTime.Now,
                UserName  = User.Identity.Name
            };

            foreach (ShoppingCartItem item in shoppingCart.Items)
            {
                order.OrderLines.Add(new OrderLine
                {
                    Order     = order,
                    OrderID   = order.OrderID,
                    ProductID = item.ProductId,
                    Quantity  = item.Quantity
                });
            }

            this.orderService.SubmitOrder(order);
            ShoppingCartBinder.Clear();
            return(View());
        }
Пример #2
0
        public ActionResult Remove(string productId)
        {
            ShoppingCart     shoppingCart = ShoppingCartBinder.GetShoppingCart();
            ShoppingCartItem cartItem     = shoppingCart.Items.FirstOrDefault(item => item.ProductId == productId);

            if (null != cartItem)
            {
                shoppingCart.Items.Remove(cartItem);
            }
            return(RedirectToAction("ShoppingCart"));
        }
Пример #3
0
 public ActionResult ShoppingCart(string productId, string productName, decimal price, [ModelBinder(typeof(ShoppingCartBinder))] ShoppingCart shoppingCart)
 {
     shoppingCart.Add(productId, productName, price);
     return(View(ShoppingCartBinder.GetShoppingCart()));
 }