Esempio n. 1
0
        public async Task Show()
        {
            ConsoleHelper.DefaultColor = ConsoleColor.Blue;
            ConsoleHelper.ColorWriteLine(ConsoleColor.Yellow, "Ingredient Menu");
            Console.WriteLine();
            ConsoleHelper.ColorWriteLine("1.) New Ingredient");
            ConsoleHelper.ColorWriteLine("2.) Lookup Ingredient");
            ConsoleHelper.ColorWriteLine("3.) Show Ingredient List");
            ConsoleHelper.ColorWriteLine("4.) Delete Ingredient");
            Console.WriteLine();
            ConsoleHelper.ColorWriteLine(ConsoleColor.Red, "5.) Back to Main Menu");
            Console.WriteLine();

            string input  = string.Empty;
            int    option = 0;
            bool   valid  = false;

            while (!valid)
            {
                ConsoleHelper.ColorWrite(ConsoleColor.Yellow, "Please select an option: ");
                input = Console.ReadLine();

                valid = ConsoleHelper.ValidateInt(input, (int)IngredientMenuOption.NewIngredient, (int)IngredientMenuOption.GoBack, out option);

                if (!Enum.IsDefined(typeof(IngredientMenuOption), option))
                {
                    _logger.LogWarning("Option is not in enum");
                    valid = false;
                }
            }

            IngredientMenuOption choice = (IngredientMenuOption)option;

            await ExecuteMenuSelection(choice);
        }
Esempio n. 2
0
        private async Task ExecuteMenuSelection(IngredientMenuOption option)
        {
            switch (option)
            {
            case IngredientMenuOption.InValid:
                _logger.LogWarning("Attempted to execute invalid menu selection");
                break;

            case IngredientMenuOption.NewIngredient:
                await NewIngredient();

                break;

            case IngredientMenuOption.LookUpIngredient:
                await LookupIngredient();

                break;

            case IngredientMenuOption.ShowIngredient:
                await ListIngredients();

                break;

            case IngredientMenuOption.DeleteIngredient:
                await DeleteIngredient();

                break;

            case IngredientMenuOption.GoBack:
                Console.WriteLine();
                break;

            default:
                break;
            }
        }