public void AddItem(Product product, int quantity)
        {
            ShoppingCartItemModel item = items.SingleOrDefault(
                p => p.Product.ProductID ==
                product.ProductID);

            //  Item does not currently exist in shopping cart
            if (item == null)
            {
                items.Add(new ShoppingCartItemModel
                {
                    Product  = product,
                    Quantity = quantity
                });
            }
            //  Otherwise, product exists in current shopping cart
            else
            {
                item.Quantity += quantity;
            }
        }
예제 #2
0
        public void AddItem(Product product, int quantity)
        {
            ShoppingCartItemModel item = Items.SingleOrDefault(
                p => p.Product.ProductID ==
                product.ProductID);

            if (item == null)
            {
                items.Add(new ShoppingCartItemModel
                {
                    Product  = product,
                    Quantity = quantity
                }
                          );
            }

            else
            {
                item.Quantity += quantity;
            }
        }