Example #1
0
        public void AddItem(Product product, int quantity)
        {
            CartItem cartItem = ItemsInCart.Where(p => p.Product.ID == product.ID).FirstOrDefault();

            if (cartItem == null)
            {
                ItemsInCart.Add(new CartItem {
                    Product = product, Quantity = quantity
                });
            }
            else
            {
                cartItem.Quantity += quantity;
            }
            CartContentChanged?.Invoke(this, new CartChangedArgs(this));
        }
Example #2
0
        public void RemoveItem(Product product, int quantity)
        {
            CartItem cartItem = ItemsInCart.Where(p => p.Product.ID == product.ID).FirstOrDefault();

            if (cartItem != null)
            {
                if (cartItem.Quantity <= quantity)
                {
                    RemoveItem(product);
                }
                else
                {
                    cartItem.Quantity -= quantity;
                }

                CartContentChanged?.Invoke(this, new CartChangedArgs(this));
            }
        }
Example #3
0
 private void RaiseCartContentChanged(IProduct product, int amount, bool added)
 {
     CartContentChanged?.Invoke(this, new CartContentChangedEventArgs(product, amount, added, GetTransactionValue()));
 }
Example #4
0
 public void Empty()
 {
     ItemsInCart.Clear();
     CartContentChanged?.Invoke(this, new CartChangedArgs(this));
 }