Example #1
0
        public ActionResult Checkout(EditAndCheckoutViewModel viewModel, Cart cart)
        {
            // take products from cart and update quantity
            foreach (var item in viewModel.CartLines)
            {
                CartLineViewModel item1 = item;
                cart.Items.Single(x => x.Product.Id == item1.ProductId).Quantity = item.Quantity;
            }

            if (CurrentUser() == null)
            {
                return View("LoginOrRegister");
            }

            int i = 0;
            foreach (CartItem cartItem in cart.Items)
            {
                cartItem.Product = daoTemplate.FindByID<Product>(cartItem.Product.Id);
                if (cartItem.Product.Rest() < cartItem.Quantity)
                    ModelState.AddModelError(string.Format("CartLines[{0}].Quantity", i), "Слишком большое количество");
                i++;
            }
            if (!ModelState.IsValid)
            {
                return View("Review", new ReviewCartViewModel
                {
                    Cart = cart
                });
            }
            return RedirectToAction("EnterShippingDetails");
        }
Example #2
0
 public ActionResult Recalc(EditAndCheckoutViewModel viewModel, Cart cart)
 {
     // take products from cart and update quantity
     foreach (var item in viewModel.CartLines)
     {
         CartLineViewModel item1 = item;
         cart.Items.Single(x => x.Product.Id == item1.ProductId).Quantity = item.Quantity;
     }
     int i = 0;
     foreach (CartItem cartItem in cart.Items)
     {
         cartItem.Product = daoTemplate.FindByID<Product>(cartItem.Product.Id);
         if (cartItem.Product.Rest() < cartItem.Quantity)
             ModelState.AddModelError(string.Format("CartLines[{0}].Quantity", i), "Слишком большое количество");
         i++;
     }
     return View("Review", new ReviewCartViewModel { Cart = cart });
 }