Exemple #1
0
 /// <summary>
 /// store's behavior to validate an order based on current product quantity
 /// </summary>
 public bool CheckInventory(COrder order)
 {
     foreach (var purchasedProduct in order.ProductList)
     {
         string   uniqueID = purchasedProduct.UniqueID;
         CProduct storage;
         if (Inventory.TryGetValue(uniqueID, out storage))
         {
             // found but not enough
             if (storage.Quantity < purchasedProduct.Quantity)
             {
                 return(false);
             }
             // enough
             else
             {
                 // one product's quantity has qualified
             }
         }
         else
         {
             // not found
             return(false);
         }
     }
     return(true);
 }
Exemple #2
0
 /// <summary>
 /// store's behavior to restock
 /// add a product's quantity if it already exists, otherwise create a new pair
 /// </summary>
 public void AddProducts(IEnumerable <CProduct> supply)
 {
     foreach (var product in supply)
     {
         CProduct temp;
         if (Inventory.TryGetValue(product.UniqueID, out temp))
         {
             Inventory[product.UniqueID].Quantity += product.Quantity;
         }
         else
         {
             Inventory[product.UniqueID] = product;
         }
     }
 }