public CartService(Models.Cart.Cart cart, IRepository <FoodItem> repository, IRepository <Order> orderRepository, UserManager <ApplicationUser> userManager) { _cart = cart; _repository = repository; _orderRepository = orderRepository; _userManager = userManager; }
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; }
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; }
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; }
public void RemoveAll() { Cart = new Models.Cart.Cart { Items = new List <CartItem>() }; }