示例#1
0
        //cart получаем из CartModelBinder
        public RedirectToActionResult AddToCart(Cart cart, int gameId, string returnUrl)
        {
            Game game = _repository.Games.FirstOrDefault(g => g.GameId == gameId);

            if (game != null)
            {
                cart.AddItem(game, 1);
                CartModelBinder.SetUpCart(cart, HttpContext.Session);
            }
            return(RedirectToAction("Index", new { returnUrl }));
        }
示例#2
0
        public RedirectToActionResult RemoveFromCart(Cart cart, int gameId, string returnUrl)
        {
            Game game = _repository.Games.FirstOrDefault(g => g.GameId == gameId);

            if (game != null)
            {
                cart.RemoveLine(game);
                if (HttpContext != null)
                {
                    CartModelBinder.SetUpCart(cart, HttpContext.Session);
                }
            }
            return(RedirectToAction("Index", new { returnUrl }));
        }
示例#3
0
 public ViewResult Checkout(Cart cart, ShippingDetails shippingDetails)
 {
     if (cart.Lines.Count() == 0)
     {
         ModelState.AddModelError("", "Извените ваша корзина пуста");
     }
     if (ModelState.IsValid)
     {
         _processor.ProcessOrder(cart, shippingDetails);
         cart.Clear();
         if (HttpContext != null)
         {
             CartModelBinder.SetUpCart(cart, HttpContext.Session);
         }
         return(View("Completed"));
     }
     else
     {
         return(View(shippingDetails));
     }
 }