/// <summary> /// Method to add those items to the cart, which will be priced based on their quantity. /// If the same item availble it will only increase the quantity of that item. /// </summary> /// <param name="product">An instance of the prodoct needs to be added to the cart</param> /// <param name="quantity">The countity of the added product</param> public void AddQuantityItem(Product product, int quantity) { // Searching for the similar product inthe cart LineItem item = _lineItems.FirstOrDefault(l => l.Product.ProductId == product.ProductId); if (item == null) { _lineItems.Add(new QuantityItem(product, quantity)); } else { ((QuantityItem)item).Quantity += quantity; } }
/// <summary> /// Method to add those items to the cart, which will be priced based on their weight. /// </summary> /// <param name="product">An instance of the prodoct needs to be added to the cart</param> /// <param name="weight">The countity of the added product</param> public void AddWeightItem(Product product, double weight) { _lineItems.Add(new WeightItem(product, weight)); }
public WeightItem(Product product, double weight) : base(product) { Weight = weight; }
public QuantityItem(Product product, int quantity) : base(product) { Quantity = quantity; }
protected LineItem(Product product) { Product = product; }
/// <summary> /// A method to remove an item from the cart /// </summary> /// <param name="product">The product that needs to be removed from the cart</param> public void RemoveLineItem(Product product) { _lineItems.RemoveAll(l => l.Product.ProductId == product.ProductId); }