public void addToCart(Coffee coffee, int quantity, int n) { CartLine line = lineCollection.Where(l => l.Coffee.CoffeeID == coffee.CoffeeID).FirstOrDefault(); if (line == null) { lineCollection.Add(new CartLine() { Coffee = coffee, Quantity = quantity, N = n}); } else if ((line.Quantity + quantity) > line.maxQuantity) { line.Quantity = line.maxQuantity; throw new Exception("You've reached maxQuantity for this coffee"); } else { line.Quantity += quantity; } }
public void RemoveFromCart(Coffee coffee) { lineCollection.RemoveAll(l => l.Coffee.CoffeeID == coffee.CoffeeID); }