Пример #1
0
        public ViewResult Checkout(Cart cart, DeliveryDTO deliveryDto)
        {
            if (cart.Lines.Count() == 0)
            {
                ModelState.AddModelError("", "Извините, ваша корзина пуста!");
            }

            if (ModelState.IsValid)
            {
                //todo: refactor
                var userId = User.Identity.GetUserId();
                var client = _clientLogic.Get(userId);

                foreach (var item in cart.Lines)
                {
                    var good = _goodLogic.Get(item.Good.Id);
                    if (good.Count >= item.Number)
                    {
                        good.Count -= item.Number;
                        good.OrderItems = null;
                        _goodLogic.Edit(good);
                    }
                    else
                    {
                        return View("GoodIsOver");
                    }
                }

                _orderLogic.ProcessOrder(cart, deliveryDto, client);
                cart.Clear();

                return View("Completed");
            }
            return View(deliveryDto);
        }
Пример #2
0
        public ActionResult Checkout(Cart cart)
        {
            var userId = User.Identity.GetUserId();
            var client = _clientLogic.Get(userId);

            if (client.IsBlocked)
            {
                return RedirectToAction("Index", "Goods");
            }

            return View(new DeliveryDTO());
        }
Пример #3
0
        public RedirectToRouteResult AddToCart(Cart cart, int goodId, string returnUrl)
        {
            var good = _goodLogic.GetAll()
                .FirstOrDefault(g => g.Id == goodId);

            if (good != null)
            {
                cart.AddItem(good, 1);
            }

            return RedirectToAction("Index", new {returnUrl});
        }
Пример #4
0
        public object BindModel(ControllerContext controllerContext,
            ModelBindingContext bindingContext)
        {
            Cart cart = null;
            if (controllerContext.HttpContext.Session != null)
            {
                cart = (Cart) controllerContext.HttpContext.Session[sessionKey];
            }

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

            return cart;
        }
Пример #5
0
 public PartialViewResult Summary(Cart cart)
 {
     return PartialView(cart);
 }
Пример #6
0
        public RedirectToRouteResult RemoveFromCart(Cart cart, int goodId, string returnUrl)
        {
            var good = _goodLogic.Get(goodId);

            if (good != null)
            {
                cart.RemoveLine(good);
            }

            return RedirectToAction("Index", new {returnUrl});
        }
Пример #7
0
        public ActionResult Index(Cart cart, string returnUrl)
        {
            var cartIndexViewModel = new CartIndexViewModel
            {
                Cart = cart,
                ReturnUrl = returnUrl
            };

            var client = _clientLogic.Get(User.Identity.GetUserId());
            if (client != null)
            {
                ViewBag.userBlocked = client.IsBlocked;
            }

            return View(cartIndexViewModel);
        }