Exemplo n.º 1
0
        static void Main(string[] args)
        {
            MenuRepository Repository = new MenuRepository();

            while (true)
            {
                Console.Clear();
                Console.WriteLine("Commands:\nAdd: 'add'\nList: 'list'\nDelete: 'delete'");
                string Command = Console.ReadLine().ToLower();
                if (Command == "add")
                {
                    MenuItem newItem = NewMenuItem();
                    Repository.AddItem(newItem);
                }
                else if (Command == "list")
                {
                    Console.Clear();
                    foreach (MenuItem Item in Repository.GetMenuItems())
                    {
                        Console.WriteLine($"[{Item.OrderNumber}]: {Item.OrderName}, \n    {Item.Description}, \n    {Item.Ingredients}, \n    ${Item.Price}");
                    }
                    Console.WriteLine("Press Enter to continue.");
                    Console.Read();
                }
                else if (Command == "delete")
                {
                    Console.Clear();
                    Console.WriteLine("What Order Number would you like to remove?");
                    int OrderNumber = Int32.Parse(Console.ReadLine());
                    Repository.RemoveItem(OrderNumber);
                    Console.WriteLine("Item Removed. Press Enter to continue.");
                    Console.Read();
                }
            }
        }
Exemplo n.º 2
0
        public void Run()
        {
            List <string> exampleIngredients = new List <string>();

            exampleIngredients.Add("example1");
            exampleIngredients.Add("example2");
            exampleIngredients.Add("example3");
            exampleIngredients.Add("example4");

            var menuItems = new List <Menu>()
            {
                new Menu("Cheeseburger", 1, exampleIngredients, "Basic Cheeseburger", 2.99m),
                new Menu("Chicken Nuggets", 2, exampleIngredients, "5 piece chicken nuggets", 1.99m),
                new Menu("Garden Salad", 3, exampleIngredients, "Salad with ranch dressing", 3.99m),
            };

            _menuRepo.AddItems(menuItems);

            while (loop)
            {
                string menuInput = ConsoleMenu();
                switch (menuInput)
                {
                case "1":
                    Menu Item = AddToMenu();
                    _menuRepo.AddItem(Item);
                    Console.Clear();
                    break;

                case "2":
                    List <Menu> OrderedList = _menuRepo.SortedMenu();
                    MenuSetup(OrderedList);
                    Console.WriteLine("Press any key to continue");
                    Console.ReadKey();
                    Console.Clear();
                    break;

                case "3":
                    Console.WriteLine("Enter the number of the item you would like to remove:");
                    int itemNumber = int.Parse(Console.ReadLine());
                    _menuRepo.RemoveItem(itemNumber);
                    Console.Clear();
                    break;

                case "X":
                    loop = false;
                    break;

                default:
                    Console.Clear();
                    Console.WriteLine("Unknown Input");
                    Console.WriteLine("Press any key to continue");
                    Console.ReadKey();
                    Console.Clear();
                    break;
                }
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            MenuRepository menuRepo = new MenuRepository();
            List <Menu>    menu     = menuRepo.DisplayList();

            string outPut    = null;
            int    itemCount = 0;

            while (true)
            {
                //Menu
                Console.Clear();
                Console.Write($"{outPut}" +
                              $"What action would you like to do?\n" +
                              $"1. Add Item to Menu\n" +
                              $"2. View List\n" +
                              $"3. Remove Item\n" +
                              $"4. Exit\n" +
                              $"   ");
                outPut = null;

                string response = Console.ReadLine();

                //AddItem
                if (response == "1")
                {
                    Console.Clear();
                    Console.Write("Enter the name of the item: ");
                    string newName = Console.ReadLine();

                    Console.Write($"Enter the description for the {newName}: ");
                    string newDesc = Console.ReadLine();

                    Console.Write($"Enter the list of ingredients for the {newName}: ");
                    string newIngredients = Console.ReadLine();

                    Console.Write($"Enter the price for the {newName}: ");
                    decimal newPrice = 0m;
                    bool    valid    = false;
                    while (!valid)
                    {
                        string input = Console.ReadLine();
                        if (decimal.TryParse(input, out newPrice))
                        {
                            valid = true;
                        }
                        else
                        {
                            Console.WriteLine("Invalid input, please enter a number.");
                        }
                    }

                    menuRepo.AddItem(newName, newDesc, newIngredients, newPrice);

                    itemCount++;
                    outPut = $"{newName} has been added to the menu as item number {itemCount}.\n";
                }

                //View List
                else if (response == "2")
                {
                    Console.Clear();
                    foreach (var item in menu)
                    {
                        Console.WriteLine($"{item.MealNumber}. {item.MealName}\n" +
                                          $"   Description: {item.MealDescription}\n" +
                                          $"   Ingredients: {item.MealIngredients}\n" +
                                          $"   Price: ${item.MealPrice}\n");
                    }
                    if (menu.Count() == 0)
                    {
                        Console.WriteLine("The Menu is currently empty.");
                    }
                    Console.ReadLine();
                }

                //Remove Item
                else if (response == "3")
                {
                    Console.Clear();
                    if (menu.Count() == 0)
                    {
                        Console.WriteLine("The Menu is currently empty.");
                        Console.ReadLine();
                    }
                    else
                    {
                        int num;

                        Console.Write("Enter the menu item number you want to remove: ");
                        bool isNumber = Int32.TryParse(Console.ReadLine(), out num);
                        if (isNumber)
                        {
                            foreach (Menu item in menu)
                            {
                                if (num == item.MealNumber)
                                {
                                    Console.Write($"Are you sure you would like to delete {item.MealName} from the menu?\n" +
                                                  $"(Y/N): ");
                                    string delResponse = Console.ReadLine().ToLower();
                                    if (delResponse == "y")
                                    {
                                        num--;
                                        menuRepo.RemoveItem(menu[num]);
                                        outPut = $"{item.MealName} has been removed to the menu.\n";

                                        foreach (Menu oldItem in menu)
                                        {
                                            int spot = menu.IndexOf(oldItem);
                                            spot++;
                                            oldItem.MealNumber = spot;
                                        }
                                        itemCount--;
                                    }
                                    break;
                                }
                            }
                        }
                        else
                        {
                            Console.WriteLine("Invalid input, please enter the menu item ID number");
                            Console.ReadLine();
                        }
                    }
                }

                else if (response == "4")
                {
                    break;
                }

                else
                {
                    outPut = "Improper input. Please try again.\n";
                }
            }
        }