public void Add(Product product, int quantity = 1) { CartEntry cartEntry = Entries.Where(ce => ce.Reference == product.Reference).FirstOrDefault(); if (cartEntry == null) { Entries.Add(new CartEntry { Product = product, Quantity = quantity, Reference = product.Reference }); } else { cartEntry.Quantity += quantity; } }
public void Remove(string reference, int quantity = 1) { CartEntry cartEntry = Entries.Where(ce => ce.Reference == reference).FirstOrDefault(); if (cartEntry != null) { if (quantity >= cartEntry.Quantity) { Entries.Remove(cartEntry); } else { cartEntry.Quantity -= quantity; } } }