public IInventoryCollection Dispense(string id, IAmount amount, int count)
 {
     if (inventory.ContainsKey(id))
     {
         if (count >= inventory[id].GetCount())
         {
             if (inventory[id].GetItemPrice() * count >= amount.GetValue())
             {
                 inventory[id] = inventory[id].UpdateCount(count);
                 if (!soldItems.ContainsKey(id))
                 {
                     soldItems.Add(id, new SoldItemInventory(inventory[id].GetItem(), count));
                 }
                 else
                 {
                     soldItems[id].UpdateCount(count);
                 }
                 soldItemPrice.Add(id, count * inventory[id].GetItemPrice());
             }
             else
             {
                 logger.Error($"Not enough money to dispense {count} items of price {count* inventory[id].GetItemPrice()}");
             }
         }
         else
         {
             logger.Error("not enough item(s) to dispense");
         }
     }
     else
     {
         logger.Error("Item not present in machine");
     }
     return(this);
 }
示例#2
0
        static async void Test()
        {
            await Income();
            await Pay();

            Console.WriteLine($"henry actor:{await henry.GetValue()} | ken actor:{await ken.GetValue()}");
        }