Esempio n. 1
0
        private async Task GetRandomJokesByCount(IConsolePrinterService printer, bool randomPerson, string category)
        {
            printer.PrintMessage(Constants.JokesCountPrompt);
            char key = keyMapper.GetEnteredKey(Console.ReadKey());

            // check if the joke count is a valid integer
            if (Int32.TryParse(key.ToString(), out int n))
            {
                printer.PrintNewline();
                string[] results = await GetRandomJokesAsync(randomPerson?await GetRandomPersonAsync() : null, category, n);

                PrintResults(printer, results);
            }
            else
            {
                printer.PrintNewline();
                printer.PrintErrorMessage(Constants.ErrorInvalidJokeCount);
            }
        }