public virtual void RemoveItem(Product product, int quantity) { var line = CartLineCollection.FirstOrDefault(p => p.Product.ProductId == product.ProductId); if (line != null) { if (quantity >= line.Quantity) { CartLineCollection.Remove(line); } else { line.Quantity -= quantity; } } }
public virtual void AddItem(Product product, int quantity) { var line = CartLineCollection.FirstOrDefault(p => p.Product.ProductId == product.ProductId); if (line == null) { CartLineCollection.Add(new CartLine { Product = product, Quantity = quantity }); } else { line.Quantity += quantity; } }