Exemplo n.º 1
0
        public int AddProduct(IProduct product, int amount = 1)
        {
            bool exist = CartProductIds.Contains(product.GetId());

            if (exist)
            {
                ICartItem item = CartItems.Find(cartItem => cartItem.GetProduct().Equals(product));
                if (item == null)
                {
                    throw new InvalidOperationException("Item exist in HashSet but not in CartItems");
                }
                return(item.IncreaseAmountOn(amount));
            }

            CartProductIds.Add(product.GetId());
            CartItems.Add(new CartItem(product, this, amount));
            return(amount);
        }