Пример #1
0
        public void AddItem(ProductModel product, int quantity)
        {
            if (quantity < 0)
            {
                RemoveItem(product, -quantity);
                return;
            }
            CartLine line = cartLines
                            .Where(p => p.Product.ProductId == product.ProductId)
                            .FirstOrDefault();

            if (line == null)
            {
                cartLines.Add(new CartLine {
                    Product = product, Quantity = quantity, ProductId = product.ProductId
                });
            }
            else
            {
                line.Quantity += quantity;
            }
        }
Пример #2
0
        public void AddItem(Product product, int quantity)
        {
            CartLine line = lineCollection
                            .Where(g => g.Product.Id == product.Id)
                            .FirstOrDefault();

            for (int i = 0; i < quantity; i++)
            {
                Products.Add(product);
            }

            if (line == null)
            {
                lineCollection.Add(new CartLine
                {
                    Product  = product,
                    Quantity = quantity
                });
            }
            else
            {
                line.Quantity += quantity;
            }
        }