/// <summary>
        /// display the current account information
        /// </summary>
        public void DisplayAccountInfo(Salesperson salesperson)
        {
            //
            // set up the console
            //
            ConsoleUtil.HeaderText = "Account Information";
            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage($"First Name: {ConsoleUtil.UppercaseFirst(salesperson.FirstName)}");
            ConsoleUtil.DisplayMessage($"Last Name: {ConsoleUtil.UppercaseFirst(salesperson.LastName)}");
            ConsoleUtil.DisplayMessage($"Age: {salesperson.Age}");
            ConsoleUtil.DisplayMessage($"Account ID: {salesperson.AccountID}");
            ConsoleUtil.DisplayMessage($"Rank: {salesperson.Rank}");

            DisplayContinuePrompt();
        }
Exemple #2
0
        /// <summary>
        /// A general method to get values from an enum from the user
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="maxAttempts"></param>
        /// <param name="userPrompt"></param>
        /// <param name="returnValue"></param>
        /// <returns></returns>
        public static bool GetEnumValueFromUser <T>(int maxAttempts, string userPrompt, out T returnValue, bool enterCancelsOut = false) where T : struct, IConvertible
        {
            //
            // declare values
            //
            bool   validInput = true;
            int    attempts   = 0;
            string userResponse;

            returnValue = default(T);

            do
            {
                if (validInput)
                {
                    ConsoleUtil.DisplayPromptMessage(userPrompt);
                }
                else
                {
                    //
                    // Show the user some valid values for the enum
                    //
                    ConsoleUtil.DisplayMessage("\nValid values are: ");
                    foreach (var item in Enum.GetValues(typeof(T)))
                    {
                        ConsoleUtil.DisplayMessage("(" + item + ")");
                    }
                    ConsoleUtil.DisplayPromptMessage("Please enter a valid value: ");
                }

                //
                // get the user response
                //
                userResponse = ConsoleUtil.UppercaseFirst(Console.ReadLine());

                if (enterCancelsOut && userResponse == "")
                {
                    return(false);
                }

                validInput = Enum.TryParse <T>(userResponse, out returnValue);

                attempts++;
            }while (!validInput && attempts < maxAttempts);

            return(validInput);
        }