コード例 #1
0
        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;
                }
            }
        }
コード例 #2
0
        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;
            }
        }