Example #1
0
        public async Task <IActionResult> AddToCart(Game game)
        {
            var gameToAdd   = _context.Game.SingleOrDefault(g => g.GameID == game.GameID);
            var cartToAddTo = CartLogic.GetCart(_context, HttpContext);

            cartToAddTo.AddToCart(gameToAdd);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> EmptyCart()
        {
            var cartToEmpty = CartLogic.GetCart(_context, HttpContext);
            await cartToEmpty.RestoreStock();

            await cartToEmpty.EmptyCart();

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(ShowCarts)));
        }
        public async Task <IActionResult> ShowCarts()
        {
            var cart     = CartLogic.GetCart(_context, HttpContext);
            var thisCart = await cart.GetCartItems();

            if (!thisCart.Any())
            {
                return(RedirectToAction(nameof(SendBackToStore)));
            }

            return(View(thisCart));
        }
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var cart = CartLogic.GetCart(_context, HttpContext);

            await cart.RemoveFromCartAsync(id);

            await _context.SaveChangesAsync();

            await cart.SetCartTotal();

            return(RedirectToAction(nameof(ShowCarts)));
        }
        public async Task <IActionResult> AddToCart(int id)
        {
            var gameToAdd   = _context.Game.SingleOrDefault(g => g.ID == id);
            var cartToAddTo = CartLogic.GetCart(_context, HttpContext);

            await cartToAddTo.AddToCart(gameToAdd);

            await _context.SaveChangesAsync();

            await cartToAddTo.SetCartTotal();

            return(RedirectToAction(nameof(ShowCarts)));
        }
Example #6
0
        public async Task <IActionResult> Create([Bind("OrderId,FirstName,LastName,IdentityNo,Address,PostalCode,City,Email,Phone,Total,OrderCreationDate")] Order order)
        {
            var cart = CartLogic.GetCart(_context, HttpContext);
            await cart.SetOrderIdNo(order);

            if (ModelState.IsValid)
            {
                _context.Add(order);
                HttpContext.Session.Clear();
                await _context.SaveChangesAsync();
            }

            return(RedirectToAction(nameof(Details), order));
        }
        public IActionResult ShowSuggestion()
        {
            var cart       = CartLogic.GetCart(_context, HttpContext);
            var suggestion = cart.GetSuggestion();

            if (suggestion == null)
            {
                return(NotFound());
            }

            int length = suggestion.Count();

            Random rand      = new Random();
            int    randIndex = rand.Next(0, length);

            return(View(suggestion[randIndex]));
        }
Example #8
0
        // GET: api/Cart/2 Read
        public Cart Get(int id)
        {
            CartLogic cl = new CartLogic();

            return(cl.GetCart(id));
        }