示例#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);
 }