private async Task SelectProductToUpdate(IReadOnlyList <TopProductDto> products)
        {
            _printer.Clear();
            _printer.WriteLine("CHANNEL ENGINE CONSOLE\n");
            _printer.WriteLine("Choose product:");
            for (var i = 0; i < products.Count; i++)
            {
                _printer.WriteLine($"{i + 1}) {products[i].MerchantProductNo} {products[i].Name}");
            }

            _printer.WriteLine("0) Return to main menu");
            _printer.WriteLine();
            var key = Console.ReadKey();

            while (!IsValidInputOption(key, products.Count))
            {
                _printer.WriteLine("\nInvalid option selected. Try again...");
                key = Console.ReadKey();
            }

            if (key.Key == ConsoleKey.D0)
            {
                return;
            }

            var keyValue = ConsoleKeyUtilities.GetIntFromDigitKey(key);

            await UpdateProductStock(products[keyValue - 1]);
        }
Beispiel #2
0
 protected virtual void RenderMenu(CommandContext context, IReadOnlyList <MenuEntry> menuEntries)
 {
     foreach (var menuEntry in menuEntries.OrderBy(m => m.Key))
     {
         Console.WriteLine(" {0}. {1}", ConsoleKeyUtilities.AsUserString(menuEntry.Key), menuEntry.Text);
     }
     Console.WriteLine();
 }
        private bool IsValidInputOption(ConsoleKeyInfo key, int optionsCount)
        {
            if (!char.IsDigit(key.KeyChar))
            {
                return(false);
            }

            var value = ConsoleKeyUtilities.GetIntFromDigitKey(key);

            return(value >= 0 && value <= optionsCount);
        }