Exemple #1
0
 /// <summary>
 /// Allocate items from the order to a
 /// </summary>
 /// <param name="itemName">Input item name</param>
 /// <param name="itemAmount">Input item amount</param>
 /// <returns></returns>
 public int AllocateItem(string inventoryName, int inventoryAmount)
 {
     if (InventoryAmounts.ContainsKey(inventoryName))
     {
         int notAllocated = inventoryAmount;
         //Check if there is free space in inventory for certain item
         if (InventoryAmounts[inventoryName] >= notAllocated)
         {
             _storedInventory.Add(inventoryName, notAllocated);
             _inventoryAmounts[inventoryName] -= notAllocated;
             return(0);
         }
         else // inventoryAmounts[inventoryName] < inventoryAmount
         {
             notAllocated = notAllocated - InventoryAmounts[inventoryName]; //decrease not allocated item variable
             _storedInventory.Add(inventoryName, InventoryAmounts[inventoryName]); //add allocated item to a stored items Collection
             _inventoryAmounts[inventoryName] = 0;                                 //assign to zero available space for storage.
             return(notAllocated);
         }
     }
     else
     {
         return(-1);
     }
 }
Exemple #2
0
 /// <summary>
 /// Set "free space" for the item in Inventoryamount Dictionary
 /// </summary>
 /// <param name="inventoryName">Input item name</param>
 /// <param name="inventoryAmount">Input item amount</param>
 public void SetInventoryAmount(string inventoryName, int inventoryAmount)
 {
     if (InventoryAmounts.ContainsKey(inventoryName))
     {
         //if we add more inventory to a warehouse to an existing item
         _inventoryAmounts[inventoryName] += inventoryAmount;
     }
     else
     {
         //if we add brand new item
         _inventoryAmounts.Add(inventoryName, inventoryAmount);
     }
 }