Пример #1
0
        /// <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;
            }
        }
Пример #2
0
 /// <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));
 }
Пример #3
0
 public WeightItem(Product product, double weight)
     : base(product)
 {
     Weight = weight;
 }
Пример #4
0
 public QuantityItem(Product product, int quantity)
     : base(product)
 {
     Quantity = quantity;
 }
Пример #5
0
 protected LineItem(Product product)
 {
     Product = product;
 }
Пример #6
0
 /// <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);
 }