Esempio n. 1
0
        private TVShow DisplayTVShowMenu(TVShow[] showArray)
        {
            int    userSelection = -1;
            string userInput     = "INITIAL";
            string exitCharUpper = "X";
            int    numberOfShows = showArray.Count();

            while (MenuHelpers.StringIsNotNumericOrExitChar(userInput, exitCharUpper))
            {
                userInput = DisplayListOfShows(showArray, exitCharUpper);
                if (userInput.IsNumeric())
                {
                    userSelection = userInput.ToInt();
                    if ((userSelection >= 0) && (userSelection < numberOfShows))
                    {
                        return(showArray[userSelection]);
                    }
                    else
                    {
                        Console.WriteLine("That's not a valid selection, dude");
                        continue;
                        // at this point, we return to the while loop
                    }
                }
                else if (userInput.ToUpper() == exitCharUpper)
                {
                    return(null);
                }
            }
            // if user selected "X", it returns null
            // if user selected a valid number, it returns the corresponding TV Show
            // if invalid number or string that isn't "X", it stays in the loop
            // so we should never actually hit this
            return(showArray[userSelection]);
        }
Esempio n. 2
0
        private async Task DisplayResultsAndPromptToAddShow(List <TVShowFromTVDBDto> searchResults)
        {
            string userShowSelection = "INITIAL";
            string exitCharUpper     = "X";

            while (MenuHelpers.StringIsNotNumericOrExitChar(userShowSelection, exitCharUpper))
            {
                userShowSelection = DisplaySearchResults(searchResults, exitCharUpper);
                if (userShowSelection.IsNumeric())
                {
                    int userSelection = userShowSelection.ToInt();
                    int numberOfShows = searchResults.Count;
                    if ((userSelection >= 0) && (userSelection < numberOfShows))
                    {
                        TVShowFromTVDBDto selectedShow = searchResults[userSelection];
                        await ConfirmThenAddShowToDatabase(selectedShow);
                    }
                    else
                    {
                        Console.WriteLine("That's not one of the shows on the list");
                        continue;
                    }
                }
                else if (userShowSelection.ToUpper() == exitCharUpper)
                {
                    return;
                }
            }
        }