示例#1
0
        /// <summary>
        /// setup the new salesperson object with the initial data
        /// Note: To maintain the pattern of only the Controller changing the data this method should
        ///       return a Salesperson object with the initial data to the controller. For simplicity in
        ///       this demo, the ConsoleView object is allowed to access the Salesperson object's properties.
        /// </summary>
        public Salesperson DisplaySetupAccount()
        {
            Salesperson salesperson = new Salesperson();
            int         maxAttempts = 3;
            string      firstName;
            string      lastName;
            string      accountId;
            string      city;
            bool        maxAttemptsExceeded = false;

            ConsoleUtil.HeaderText = "Account Setup";
            ConsoleUtil.DisplayReset();

            firstName = ConsoleValidator.TestForEmpty(maxAttempts, "First Name:", out maxAttemptsExceeded);

            if (!string.IsNullOrEmpty(firstName))
            {
                salesperson.FirstName = firstName;
                maxAttemptsExceeded   = false;
            }
            else
            {
                return(salesperson);
            }

            lastName = ConsoleValidator.TestForEmpty(maxAttempts, "Last Name:", out maxAttemptsExceeded);

            if (!string.IsNullOrEmpty(lastName))
            {
                salesperson.LastName = lastName;
                maxAttemptsExceeded  = false;
            }
            else
            {
                return(salesperson);
            }

            accountId = ConsoleValidator.TestForEmpty(maxAttempts, "Account ID:", out maxAttemptsExceeded);

            if (!string.IsNullOrEmpty(accountId))
            {
                salesperson.AccountID = accountId;
                maxAttemptsExceeded   = false;
            }
            else
            {
                return(salesperson);
            }

            city = ConsoleValidator.TestForEmpty(maxAttempts, "City:", out maxAttemptsExceeded);

            if (!string.IsNullOrEmpty(city))
            {
                salesperson.CitiesVisited.Add(city);
                maxAttemptsExceeded = false;
            }
            else
            {
                return(salesperson);
            }

            return(salesperson);
        }