Exemple #1
0
        public int RemoveProduct(IProduct product, int amount = 1)
        {
            if (!CartProductIds.Contains(product.GetId()))
            {
                throw new InvalidOperationException("No such product in a cart");
            }

            ICartItem item = CartItems.Find(cartItem => cartItem.GetProduct().Equals(product));

            if (item == null)
            {
                throw new InvalidOperationException("Item exist in HashSet but not in CartItems");
            }

            if (item.GetAmount() != amount)
            {
                return(item.DecreaseAmountOn(amount));
            }

            // here item should be deleted
            CartProductIds.Remove(product.GetId());
            CartItems.RemoveAll(cartItem => cartItem.GetProduct().Equals(product));
            return(0);
        }
Exemple #2
0
 public double CalcPrice(ICartItem cartItem)
 {
     return(cartItem.GetAmount() * cartItem.GetPrice());
 }