コード例 #1
0
ファイル: Cart.cs プロジェクト: Kazempour/mvc
        /// <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
ファイル: Cart.cs プロジェクト: Kazempour/mvc
 /// <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
ファイル: Cart.cs プロジェクト: Kazempour/mvc
 public WeightItem(Product product, double weight)
     : base(product)
 {
     Weight = weight;
 }
コード例 #4
0
ファイル: Cart.cs プロジェクト: Kazempour/mvc
 public QuantityItem(Product product, int quantity)
     : base(product)
 {
     Quantity = quantity;
 }
コード例 #5
0
ファイル: Cart.cs プロジェクト: Kazempour/mvc
 protected LineItem(Product product)
 {
     Product = product;
 }
コード例 #6
0
ファイル: Cart.cs プロジェクト: Kazempour/mvc
 /// <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);
 }