Beispiel #1
0
        public void Add(Product product, int quantity = 1)
        {
            CartEntry cartEntry = Entries.Where(ce => ce.Reference == product.Reference).FirstOrDefault();

            if (cartEntry == null)
            {
                Entries.Add(new CartEntry {
                    Product = product, Quantity = quantity, Reference = product.Reference
                });
            }
            else
            {
                cartEntry.Quantity += quantity;
            }
        }
Beispiel #2
0
        public void Remove(string reference, int quantity = 1)
        {
            CartEntry cartEntry = Entries.Where(ce => ce.Reference == reference).FirstOrDefault();

            if (cartEntry != null)
            {
                if (quantity >= cartEntry.Quantity)
                {
                    Entries.Remove(cartEntry);
                }
                else
                {
                    cartEntry.Quantity -= quantity;
                }
            }
        }