예제 #1
0
 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);
 }
예제 #2
0
 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");
             }
         }
     }
 }