/// <summary>
        /// Prompts user for song name and artist and adds a new Song.
        /// </summary>
        static void AddSong()
        {
            bool done = false;

            do
            {
                string songName = CLI.Prompt("What's the name of the song? ");
                string artist   = CLI.Prompt("Who's the artist? ");

                _songs.Add(new Song {
                    Name = songName, Artist = artist
                });
                done = CLI.Prompt("Add another song? (y/n) ").ToLower() != "y";
            } while (!done);
        }
Esempio n. 2
0
        /// <summary>
        /// Application entry point
        /// </summary>
        /// <param name="args">The arguments.</param>
        static void Main(string[] args)
        {
            CLI.DisplayWelcome();

            int option = 0;

            while ((option = Menu.Prompt()) != 3)
            {
                switch (option)
                {
                case 1:
                    AddSong();
                    break;

                case 2:
                    DisplaySongList();
                    break;
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Displays the application menu and prompts the user for selection.
        /// </summary>
        /// <returns></returns>
        internal static int Prompt()
        {
            bool   valid        = false;
            int    parsedOption = 0;
            string option       = string.Empty;

            Display();
            do
            {
                option = CLI.Prompt($"Please select an option (1-{_options.Length}): ");
                bool canParse = int.TryParse(option, out parsedOption);
                valid = canParse && parsedOption > 0 && parsedOption <= 3;

                if (!valid)
                {
                    Console.WriteLine("'" + option + "' is not a valid option. Please provide a number 1-3");
                }
            }while (!valid);

            return(parsedOption);
        }