public void AddItem(Product product, int quantity) { CartItem cartItem = ItemsInCart.Where(p => p.Product.ID == product.ID).FirstOrDefault(); if (cartItem == null) { ItemsInCart.Add(new CartItem { Product = product, Quantity = quantity }); } else { cartItem.Quantity += quantity; } CartContentChanged?.Invoke(this, new CartChangedArgs(this)); }
public void RemoveItem(Product product, int quantity) { CartItem cartItem = ItemsInCart.Where(p => p.Product.ID == product.ID).FirstOrDefault(); if (cartItem != null) { if (cartItem.Quantity <= quantity) { RemoveItem(product); } else { cartItem.Quantity -= quantity; } CartContentChanged?.Invoke(this, new CartChangedArgs(this)); } }
private void RaiseCartContentChanged(IProduct product, int amount, bool added) { CartContentChanged?.Invoke(this, new CartContentChangedEventArgs(product, amount, added, GetTransactionValue())); }
public void Empty() { ItemsInCart.Clear(); CartContentChanged?.Invoke(this, new CartChangedArgs(this)); }