Exemplo n.º 1
0
        private void DeleteMenuItem()
        {
            List <MenuItem> menuItemList = _menuItemRepo.GetMenuItemList();

            Console.WriteLine("What menu item number do you want to delete?");
            string input = Console.ReadLine();

            if (int.TryParse(input, out int result))
            {
                int searchIndex = SearchMenu(result);
                if (searchIndex == -1)
                {
                    Console.WriteLine("Menu item not found.");
                }
                else
                {
                    Console.WriteLine("Do you want to remove menu item #" + menuItemList[searchIndex].Number + "? ('yes' or 'no')");
                    if (Console.ReadLine() == "yes")
                    {
                        Console.WriteLine("Menu item #" + menuItemList[searchIndex].Number + " has been removed.");
                        menuItemList.RemoveAt(searchIndex);
                    }
                    else
                    {
                        Console.WriteLine("No action taken.");
                    }
                }
            }
            else
            {
                Console.WriteLine("Menu item not found.");
            }
        }
        public void Run()
        {
            menuItems = _itemRepo.GetMenuItemList();
            bool isRunning = true;

            while (isRunning)
            {
                Console.WriteLine("Choose an action:" +
                                  "\n1. Create new menu item" +
                                  "\n2. Remove menu item" +
                                  "\n3. See current list" +
                                  "\n4. Exit");

                int input = int.Parse(Console.ReadLine());
                switch (input)
                {
                case 1:         //Create new content
                    List <string> MenuItem = new List <string>();
                    CreateMenu();
                    break;

                case 2:
                    RemoveMenuItem();
                    break;

                case 3:
                    PrintMenuList();
                    break;     //Show current list

                case 4:        //Exit
                    isRunning = false;
                    Console.WriteLine("Thank you come again");
                    Console.ReadLine();
                    break;

                default:
                    Console.WriteLine("Invalid response.");
                    Console.ReadLine();
                    break;
                }
            }
        }
Exemplo n.º 3
0
        private void RunMenu()
        {
            menuItem = _menuRepo.GetMenuItemList();
            bool running = true;

            while (running)
            {
                Console.WriteLine("Welcome to Komodo Cafe menu editor.\n" +
                                  "\n1. Add menu item" +
                                  "\n2. Delete menu item" +
                                  "\n3. See all menu items" +
                                  "\n0. Exit");
                int input = int.Parse(Console.ReadLine());
                switch (input)
                {
                case 1:
                    AddItem();
                    break;

                case 2:
                    DeleteItem();
                    break;

                case 3:
                    SeeAllItems();
                    break;

                case 0:
                    running = false;
                    break;

                default:
                    Console.WriteLine("Invalid Entry.");
                    break;
                }
            }
        }
Exemplo n.º 4
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();
            }
        }