コード例 #1
0
        public void DecreaseQuantity(Furniture furniture)
        {
            ShoppingCarItem item = items.Where(p => p.Furniture.FurnitureId == furniture.FurnitureId).FirstOrDefault();

            if (item != null)
            {
                item.Quantity -= 1;
            }
            if (item.Quantity == 0)
            {
                RemoveItem(furniture);
            }
        }
コード例 #2
0
        public void AddItem(Furniture furniture, int quantity)
        {
            ShoppingCarItem item = items
                                   .Where(p => p.Furniture.FurnitureId == furniture.FurnitureId)
                                   .FirstOrDefault();

            if (item == null)
            {
                items.Add(new ShoppingCarItem
                {
                    Furniture = furniture,
                    Quantity  = quantity
                });
            }
            else
            {
                item.Quantity += quantity;
            }
        }