Ejemplo n.º 1
0
        private void RemoveMealFromMenuByNumber()
        {
            Console.Clear();
            Console.WriteLine("\nWhich meal would you like to remove?" +
                              "\nPlease enter a number");
            List <Menu> mealList = _cafeRepository.ViewFullMenu();
            int         count    = 0;

            foreach (Menu meal in mealList)
            {
                count++;
                Console.WriteLine($"{count} {meal.MealName}");
            }
            int targetMealNumber = int.Parse(Console.ReadLine());
            int targetIndex      = targetMealNumber - 1;

            if (targetIndex >= 0 && targetIndex < mealList.Count)
            {
                Menu desiredMenuItem = mealList[targetIndex];
                if (_cafeRepository.DeleteExistingMeal(desiredMenuItem))
                {
                    Console.WriteLine($"{desiredMenuItem.MealName} was successfully removed.");
                }
                else
                {
                    Console.WriteLine("Attempt to remove meal selected failed.");
                }
            }
            else
            {
                Console.WriteLine("No meal has that number.");
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }