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; } }
public virtual void Clear() { CartLineCollection.Clear(); }
public virtual decimal CalculateTotal() { return(CartLineCollection.Sum(e => e.Quantity * e.Product.Price)); }