/// <summary>Displays a menu an prompts the user to select a menu item.</summary> /// <param name="menuName">The name of the menu (it's NOT case sensitive)</param> /// <param name="title">The title of the menu</param> /// <param name="breadCrumbType">The type of breadcrumb trail you would like to see.</param> public async Task DisplayMenuAsync(string menuName, string title, BreadCrumbType breadCrumbType) { var menuList = _menuRepository.LoadMenus(menuName); var instantiatedMenuList = _menuRepository.CreateMenuItems(menuList); var newMenu = new ConsoleMenuWrapper { Title = title, BreadCrumbTitle = BuildBreadCrumbTrail(breadCrumbType, title), MenuItems = instantiatedMenuList }; _menuStack.Push(newMenu); bool clearScreen = true; while (true) { ShowOneMenu(clearScreen); ConsoleMenuItemResponse response = await DoWorkAsync(); if (response.ExitMenu) { break; } clearScreen = response.ClearScreen; } _menuStack.Pop(); }
/// <summary>Displays the menu and attempts to get a menu item select from the user. /// If the user selects an item, it works is performed on that selected item.</summary> private async Task <ConsoleMenuItemResponse> DoWorkAsync() { int?userChoice = _promptHelper.GetNumber(null, 1); var result = new ConsoleMenuItemResponse(false, true); if (userChoice.HasValue) { var currentMenuItems = _menuStack.Peek(); var worker = currentMenuItems.MenuItems.FirstOrDefault(w => w.ItemNumber == userChoice.Value); if (worker == null) { ShowOneMenu(true); _console.WriteLine("*******Please enter a valid number*******"); } else { result = await worker.Item.WorkAsync(); } } else { ShowOneMenu(true); _console.WriteLine("*******Please enter a valid number*******"); } return(result); }