コード例 #1
0
 //currently AddNewItem only exists to allow me to test, if it didn't work most of the tests wouldn't pass
 public void AddNewItem(Item item, IEnumerable <Ingredient> ingredients)
 {
     if (item != null && ingredients.Count() > 0)
     {
         _serv.AddNewItem(item);
         var ingredientsWithID = new List <Ingredient>();
         foreach (var ingredient in ingredients)
         {
             if (_ingServ.GetIngredientsByName(ingredient.Name).Count() == 0)
             {
                 _ingServ.AddNewIngredient(ingredient);
             }
             ingredientsWithID.AddRange(_ingServ.GetIngredientsByName(ingredient.Name));
         }
         var itemIngredients = new List <ItemIngredients>();
         foreach (var ingredient in ingredientsWithID)
         {
             itemIngredients.Add(new ItemIngredients {
                 IngredientID = ingredient.IngredientID, ItemID = item.ItemID
             });
         }
         _iIServ.AddItemIngredients(itemIngredients);
     }
 }