Ejemplo n.º 1
0
        public void Run()
        {
            _menuItems = _menuRepo.ProduceMenu();
            SeedData();

            while (_response != 4)
            {
                PrintMenu();
                switch (_response)
                {
                case 1:
                    Console.WriteLine("Meal name: ");
                    string mealName = Console.ReadLine();

                    Console.WriteLine("\nMeal description: ");
                    var description = Console.ReadLine();

                    Console.WriteLine("\nMeal price: ");
                    decimal price = decimal.Parse(Console.ReadLine());

                    bool ingredientsLoop = true;

                    List <string> ingredientsFromConsole = new List <string>();

                    while (ingredientsLoop)
                    {
                        Console.WriteLine("Name an ingredient: ");
                        var ingredient = Console.ReadLine();
                        ingredientsFromConsole.Add(ingredient);

                        Console.WriteLine("Would you like to add another ingredient? y/n");
                        var addIngredientResponse = Console.ReadLine().ToLower();

                        if (addIngredientResponse.Contains("n"))
                        {
                            ingredientsLoop = false;
                        }
                    }
                    string ingredients = _menuRepo.IngredientsToString(ingredientsFromConsole);

                    _menuRepo.AddItemToMenu(new MenuItem(mealName, description, ingredients, price));
                    break;

                case 2:
                    PrintMeals();
                    Console.WriteLine("Which item number should be removed?");
                    var removalNum = int.Parse(Console.ReadLine());

                    _menuRepo.RemoveItemFromMenu(_menuItems[removalNum - 1]);
                    break;

                case 3:
                    PrintMeals();
                    break;
                }
                Console.WriteLine("Press any key to return to menu...");
                Console.ReadKey();
                Console.Clear();
            }
        }
Ejemplo n.º 2
0
        public void Run()
        {
            _menuItems = _menuRepo.GetMenuItemList();

            while (_response != 4)
            {
                PrintMenu();
                switch (_response)
                {
                case 1:
                    Console.WriteLine("Meal name: ");
                    var mealName = Console.ReadLine();

                    Console.WriteLine("\nMeal description: ");
                    var description = Console.ReadLine();

                    Console.WriteLine("\nMeal price: ");
                    var price = decimal.Parse(Console.ReadLine());

                    var isAddingIngredients = true;

                    var ingredientsFromConsole = new List <string>();

                    while (isAddingIngredients)
                    {
                        Console.WriteLine("Name an ingredient: ");
                        var ingredient = Console.ReadLine();
                        ingredientsFromConsole.Add(ingredient);

                        try
                        {
                            Console.WriteLine("Would you like to add another ingredient? y/n");
                            var addIngredientResponse = Console.ReadLine().ToLower();

                            if (!addIngredientResponse.Contains("n") && !addIngredientResponse.Contains("y"))
                            {
                                throw new ArgumentException("Please enter \"n\" or \"y\".");
                            }
                            if (addIngredientResponse == "n")
                            {
                                isAddingIngredients = false;
                            }
                        }
                        catch (Exception ex) { Console.WriteLine(ex.Message); }
                    }
                    string ingredients = _menuRepo.IngredientsToString(ingredientsFromConsole);

                    _menuRepo.AddItemToMenu(new MenuItem(mealName, description, ingredients, price));
                    break;

                case 2:
                    PrintMeals();
                    Console.WriteLine("Which item number should be removed?");
                    var removalNum = int.Parse(Console.ReadLine());

                    _menuRepo.RemoveItemFromMenu(_menuItems[removalNum - 1]);
                    break;

                case 3:
                    PrintMeals();
                    break;
                }
                Console.WriteLine("Press any key to return to menu...");
                Console.ReadKey();
                Console.Clear();
            }
        }