public void addProduct(ItemToPurchase itemParam) { foreach (ItemToPurchase item in itemsToPurchase) { if (item.Product == itemParam.Product) { item.Quantity += itemParam.Quantity; paymentAmount += item.Quantity * item.Product.price; Console.WriteLine("addProduct " + itemParam.Quantity); return; } } itemsToPurchase.Add(itemParam); paymentAmount += itemParam.Quantity * itemParam.Product.price; Console.WriteLine("addProduct " + itemParam.Quantity); }
public void removeProduct(ItemToPurchase itemParam) { foreach (ItemToPurchase item in itemsToPurchase) { if (item.Product == itemParam.Product) { if (item.Quantity > itemParam.Quantity) { item.Quantity -= itemParam.Quantity; paymentAmount -= itemParam.Quantity * item.Product.price; Console.WriteLine("removeProduct " + item.Quantity); } else { paymentAmount -= item.Quantity * item.Product.price; itemsToPurchase.Remove(item); Console.WriteLine("removeProduct"); } } } }