Ejemplo n.º 1
0
        private static void FormIngredientList(Recipe recipeToAdd, RecipeController recCont)
        {
            Console.WriteLine($"Enter ingredients for recipe {recipeToAdd.Name} below:");
            Console.WriteLine("Or enter -1 in any field to stop adding ingredients");

            while (true)
            {
                Console.Write("Ingredient name:");
                string name = Console.ReadLine().Trim();
                if (name == "-1")
                {
                    break;
                }

                double amount;
                bool   wasBreaked = false;
                bool   parsed     = false;
                while (true)
                {
                    Console.Write("Amount:");
                    parsed = double.TryParse(Console.ReadLine(), out amount);
                    if (parsed && amount == -1)
                    {
                        wasBreaked = true;
                        break;
                    }
                    else if (parsed)
                    {
                        break;
                    }
                }
                if (wasBreaked)
                {
                    break;
                }
                Console.Write("Measured in:");
                string denomination = Console.ReadLine().Trim();
                if (denomination == "-1")
                {
                    break;
                }
                recCont.AddIngredientToRecipe(recipeToAdd, name, denomination, amount);
            }
        }