Exemple #1
0
 public CartService(Models.Cart.Cart cart, IRepository <FoodItem> repository, IRepository <Order> orderRepository, UserManager <ApplicationUser> userManager)
 {
     _cart            = cart;
     _repository      = repository;
     _orderRepository = orderRepository;
     _userManager     = userManager;
 }
Exemple #2
0
        public void RemoveFromCart(int id)
        {
            var cart = Cart;
            var item = cart.Items.FirstOrDefault(x => x.ProductId == id);

            if (item != null)
            {
                cart.Items.Remove(item);
            }
            Cart = cart;
        }
Exemple #3
0
        public void AddToCart(int id)
        {
            var cart = Cart;
            var item = cart.Items.FirstOrDefault(x => x.ProductId == id);

            if (item != null)
            {
                item.Quantity++;
            }
            else
            {
                cart.Items.Add(new CartItem {
                    ProductId = id, Quantity = 1
                });
            }

            Cart = cart;
        }
Exemple #4
0
        public void DecrementFromCart(int id)
        {
            var cart = Cart;
            var item = cart.Items.FirstOrDefault(x => x.ProductId == id);

            if (item != null)
            {
                if (item.Quantity > 0)
                {
                    item.Quantity--;
                }

                if (item.Quantity == 0)
                {
                    cart.Items.Remove(item);
                }
            }

            Cart = cart;
        }
Exemple #5
0
 public void RemoveAll()
 {
     Cart = new Models.Cart.Cart {
         Items = new List <CartItem>()
     };
 }