/// <summary>
        ///  prompts the user to load account and travel log information
        ///  overloaded method to avoid passing a null value
        /// </summary>
        /// <param name="salesperson"></param>
        /// <param name="maxAttemptsExceeded"></param>
        /// <returns></returns>
        public bool DisplayLoadAccountInfo(Salesperson salesperson, out bool maxAttemptsExceeded)
        {
            string userResponse;

            maxAttemptsExceeded = false;

            ConsoleUtil.HeaderText = "Load Account Information";
            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage("");
            userResponse = ConsoleValidator.GetYesNoFromUser(MAXIMUM_ATTEMPTS, "Load the account information?", out maxAttemptsExceeded);

            if (maxAttemptsExceeded)
            {
                ConsoleUtil.DisplayMessage("It appears you are having difficulties. You will return to the main menu.");
                return(false);
            }
            else
            {
                // note use of ternary operator (takes three arguments)
                return(userResponse == "YES" ? true : false);
            }
        }
        /// <summary>
        /// display a list of the cities traveled
        /// </summary>
        public void DisplayCitiesTraveled(Salesperson salesperson)
        {
            ConsoleUtil.HeaderText = "Travel Log";
            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage("You have traveled to the following cities:");
            ConsoleUtil.DisplayMessage("");

            foreach (City city in salesperson.CitiesVisited)
            {
                ConsoleUtil.DisplayMessage("City: " + city.CityName.ToUpper());
                foreach (Product product in city.SalesInfo)
                {
                    ConsoleUtil.DisplayMessage("\tProduct Type: " + product.Type.ToString());
                    ConsoleUtil.DisplayMessage("\tUnits Bought: " + product.ProductsBought.ToString());
                    ConsoleUtil.DisplayMessage("\tUnits Sold: " + product.ProductsSold.ToString());
                    ConsoleUtil.DisplayMessage("");
                }
                ConsoleUtil.DisplayMessage("");
            }


            DisplayContinuePrompt();
        }
        /// <summary>
        /// method displays menu system that allow the user to update account info of their choosing
        /// </summary>
        /// <param name="salesperson"></param>
        /// <returns></returns>
        public Salesperson DisplayUpdateAccount(Salesperson salesperson)
        {
            bool usingMenu = true;

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

            while (usingMenu)
            {
                // display account details to user
                DisplayAccountDetail(salesperson);

                ConsoleUtil.DisplayMessage("");
                ConsoleUtil.DisplayMessage("Type the number for which info you wish to update: ");
                ConsoleUtil.DisplayMessage("");
                Console.Write(
                    "\t" + "1. First Name" + Environment.NewLine +
                    "\t" + "2. Last Name" + Environment.NewLine +
                    "\t" + "3. Account ID" + Environment.NewLine +
                    "\t" + "E. Main Menu" + Environment.NewLine);

                //
                // get and process the user's response
                ConsoleKeyInfo userResponse = Console.ReadKey(true);
                switch (userResponse.KeyChar)
                {
                case '1':
                    ConsoleUtil.DisplayReset();
                    ConsoleUtil.DisplayMessage("");
                    ConsoleUtil.DisplayPromptMessage("Update your first name:");
                    salesperson.FirstName = Console.ReadLine();
                    ConsoleUtil.DisplayReset();
                    break;

                case '2':
                    ConsoleUtil.DisplayReset();
                    ConsoleUtil.DisplayMessage("");
                    ConsoleUtil.DisplayPromptMessage("Update your last name:");
                    salesperson.LastName = Console.ReadLine();
                    ConsoleUtil.DisplayReset();
                    break;

                case '3':
                    ConsoleUtil.DisplayReset();
                    ConsoleUtil.DisplayMessage("");
                    ConsoleUtil.DisplayPromptMessage("Update your account ID name:");
                    salesperson.AccountID = Console.ReadLine();
                    ConsoleUtil.DisplayReset();
                    break;

                case 'E':
                case 'e':
                    usingMenu = false;
                    break;

                default:
                    ConsoleUtil.DisplayMessage(
                        "It appears you have selected an incorrect choice." + Environment.NewLine +
                        "Press any key to return to continue");
                    userResponse = Console.ReadKey(true);
                    break;
                }
            }

            DisplayContinuePrompt();

            return(salesperson);
        }
        /// <summary>
        /// This methods prompts the user for products and adds them to the list
        /// </summary>
        /// <param name="salesperson"></param>
        /// <returns></returns>
        public List <Product> DisplayGetProducts(Salesperson salesperson)
        {
            // initialize new list of products
            salesperson.CurrentStock = new List <Product>();

            bool   keepAdding = true;
            string userResponse;
            bool   maxAttemptsExceeded = false;

            Product.ProductType productType;

            while (keepAdding)
            {
                productType = GetTypeOfProduct(salesperson, "add", out bool notInStock);

                // checks to see if product already exist in inventory or is set to type none
                if (!notInStock && productType != Product.ProductType.None)
                {
                    // get number of products
                    if (ConsoleValidator.TryGetIntegerFromUser(MINIMUM_BUYSELL_AMOUNT, MAXIMUM_BUYSELL_AMOUNT, MAXIMUM_ATTEMPTS, productType.ToString(), out int numberOfUnits))
                    {
                        // add product to current stock list
                        salesperson.CurrentStock.Add(new Product(productType, numberOfUnits, false));

                        userResponse = ConsoleValidator.GetYesNoFromUser(MAXIMUM_ATTEMPTS, "Do you wish to continue adding products?", out maxAttemptsExceeded);
                        ConsoleUtil.DisplayReset();

                        if (maxAttemptsExceeded || userResponse == "NO")
                        {
                            // exit the while loop
                            keepAdding = false;
                        }
                        else
                        {
                            //display available products to user
                            DisplayAvailableProducts();
                            ConsoleUtil.DisplayMessage("");
                        }
                    }
                    else
                    {
                        ConsoleUtil.DisplayMessage("It appears you are having difficulty setting the number of products in your stock.");
                        ConsoleUtil.DisplayMessage("By default, the number of products in your inventory are now set to 0.");

                        // add product to current stock list with default number of units set to 0
                        salesperson.CurrentStock.Add(new Product(productType, 0, false));

                        userResponse = ConsoleValidator.GetYesNoFromUser(MAXIMUM_ATTEMPTS, "Do you wish to continue adding products?", out maxAttemptsExceeded);
                        ConsoleUtil.DisplayReset();

                        if (maxAttemptsExceeded || userResponse == "NO")
                        {
                            // exit the while loop
                            keepAdding = false;
                        }
                        else
                        {
                            //display available products to user
                            DisplayAvailableProducts();
                            ConsoleUtil.DisplayMessage("");
                        }
                    }
                }
                else
                {
                    ConsoleUtil.DisplayMessage(productType.ToString() + " already exist in your inventory.");

                    userResponse = ConsoleValidator.GetYesNoFromUser(MAXIMUM_ATTEMPTS, "Do you wish to continue adding products?", out maxAttemptsExceeded);
                    ConsoleUtil.DisplayReset();

                    if (maxAttemptsExceeded || userResponse == "NO")
                    {
                        // exit the while loop
                        keepAdding = false;
                    }
                    else
                    {
                        //display available products to user
                        DisplayAvailableProducts();
                        ConsoleUtil.DisplayMessage("");
                    }
                }

                if (productType == Product.ProductType.None)
                {
                    salesperson.CurrentStock.Add(new Product(Product.ProductType.None, 0, false));

                    // exit while loop
                    keepAdding = false;
                }
            }

            return(salesperson.CurrentStock);
        }
 /// <summary>
 /// Display Account Details
 /// </summary>
 /// <param name="salesperson"></param>
 private void DisplayAccountDetail(Salesperson salesperson)
 {
     ConsoleUtil.DisplayMessage("First Name: " + salesperson.FirstName);
     ConsoleUtil.DisplayMessage("Last Name: " + salesperson.LastName);
     ConsoleUtil.DisplayMessage("Account ID: " + salesperson.AccountID);
 }
        /// <summary>
        /// get the menu choice from the user
        /// </summary>
        public MenuOption DisplayGetUserMenuChoice()
        {
            MenuOption userMenuChoice = MenuOption.None;
            bool       usingMenu      = true;

            while (usingMenu)
            {
                // set up display area
                ConsoleUtil.HeaderText = "The Sales Tracker";
                ConsoleUtil.DisplayReset();
                Console.CursorVisible = false;

                // display the menu
                ConsoleUtil.DisplayMessage("Please type the number of your menu choice.");
                ConsoleUtil.DisplayMessage("");
                Console.Write(
                    "\t" + "0. Setup Account" + Environment.NewLine +
                    "\t" + "1. Update Account" + Environment.NewLine +
                    "\t" + "2. Travel" + Environment.NewLine +
                    "\t" + "3. Buy" + Environment.NewLine +
                    "\t" + "4. Sell" + Environment.NewLine +
                    "\t" + "5. Display Inventory" + Environment.NewLine +
                    "\t" + "6. Display Cities" + Environment.NewLine +
                    "\t" + "7. Display Account Info" + Environment.NewLine +
                    "\t" + "8. Save Account Info" + Environment.NewLine +
                    "\t" + "9. Load Account Info" + Environment.NewLine +
                    "\t" + "E. Exit" + Environment.NewLine);

                //
                // get and process the user's response
                // note: ReadKey argument set to "true" disables the echoing of the key press
                ConsoleKeyInfo userResponse = Console.ReadKey(true);
                switch (userResponse.KeyChar)
                {
                case '0':
                    userMenuChoice = MenuOption.SetupAccount;
                    usingMenu      = false;
                    break;

                case '1':
                    userMenuChoice = MenuOption.UpdateAccount;
                    usingMenu      = false;
                    break;

                case '2':
                    userMenuChoice = MenuOption.Travel;
                    usingMenu      = false;
                    break;

                case '3':
                    userMenuChoice = MenuOption.Buy;
                    usingMenu      = false;
                    break;

                case '4':
                    userMenuChoice = MenuOption.Sell;
                    usingMenu      = false;
                    break;

                case '5':
                    userMenuChoice = MenuOption.DisplayInventory;
                    usingMenu      = false;
                    break;

                case '6':
                    userMenuChoice = MenuOption.DisplayCities;
                    usingMenu      = false;
                    break;

                case '7':
                    userMenuChoice = MenuOption.DisplayAccountInfo;
                    usingMenu      = false;
                    break;

                case '8':
                    userMenuChoice = MenuOption.SaveAccountInfo;
                    usingMenu      = false;
                    break;

                case '9':
                    userMenuChoice = MenuOption.LoadAccountInfo;
                    usingMenu      = false;
                    break;

                case 'E':
                case 'e':
                    userMenuChoice = MenuOption.Exit;
                    usingMenu      = false;
                    break;

                default:
                    ConsoleUtil.DisplayMessage(
                        "It appears you have selected an incorrect choice." + Environment.NewLine +
                        "Press any key to continue.");
                    Console.ReadKey();
                    break;
                }
            }
            Console.CursorVisible = true;

            return(userMenuChoice);
        }
Example #7
0
        /// <summary>
        /// display a list of product types and return the selected product with cost
        /// </summary>
        public void DisplayProductUserSelection(Salesperson salesperson)
        {
            bool usingMenu           = true;
            int  maxAttempts         = 3;
            bool maxAttemptsExceeded = false;

            Product product = new Product();

            Product.ProductType productType = new Product.ProductType();

            productType = Product.ProductType.None;

            //
            // set up display area
            //
            ConsoleUtil.DisplayReset();
            ConsoleUtil.HeaderText = "Select a Product";
            Console.CursorVisible  = false;

            while (usingMenu)
            {
                //
                // set up display area
                //
                ConsoleUtil.DisplayReset();
                Console.CursorVisible = false;

                //
                // display the menu
                //
                ConsoleUtil.DisplayMessage("Please type the number of your menu choice.");
                ConsoleUtil.DisplayMessage("");
                Console.Write(
                    "\t" + "1. Furry" + Environment.NewLine +
                    "\t" + "2. Spotted" + Environment.NewLine +
                    "\t" + "3. Dancing" + Environment.NewLine);

                //
                // get and process the user's response
                // note: ReadKey argument set to "true" disables the echoing of the key press
                //
                ConsoleKeyInfo userResponse = Console.ReadKey(true);
                switch (userResponse.KeyChar)
                {
                case '1':
                    productType = Product.ProductType.Furry;
                    usingMenu   = false;
                    break;

                case '2':
                    productType = Product.ProductType.Spotted;
                    usingMenu   = false;
                    break;

                case '3':
                    productType = Product.ProductType.Dancing;
                    usingMenu   = false;
                    break;

                default:
                    ConsoleUtil.DisplayMessage(
                        "It appears you have selected an incorrect choice." + Environment.NewLine +
                        "Press any key to continue.");

                    userResponse = Console.ReadKey(true);
                    if (userResponse.Key == ConsoleKey.Escape)
                    {
                        usingMenu = false;
                    }
                    break;
                }
                product.Type = productType;
            }
            Console.Clear();

            if (!string.IsNullOrEmpty(product.Type.ToString()))
            {
                product.Cost = ConsoleValidator.TestForDouble(maxAttempts, $"{product.Type} Product Cost:", out maxAttemptsExceeded);
            }

            Console.CursorVisible    = true;
            salesperson.CurrentStock = product;
            //return product;
        }
Example #8
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);
        }
Example #9
0
        /// <summary>
        /// helper method to get a valid integer from the user within a range
        /// </summary>
        /// <param name="minValue">inclusive minimum value</param>
        /// <param name="maxValue">inclusive maximum value</param>
        /// <param name="maxAttempts">maximum number of attempts</param>
        /// <param name="pluralName">plural name of item</param>
        /// <param name="validInput">indicates valid user input</param>
        /// <returns></returns>
        public static bool TryGetIntegerFromUser(int minValue, int maxValue, int maxAttempts, string pluralName, out int userInteger)
        {
            bool   validInput          = false;
            bool   maxAttemptsExceeded = false;
            string userResponse;
            string feedbackMessage = "";
            int    attempts        = 1;

            userInteger = 0;

            while (!validInput && !maxAttemptsExceeded)
            {
                //
                // more attempts available
                //
                if (attempts <= maxAttempts)
                {
                    ConsoleUtil.DisplayPromptMessage($"Enter the number, between {minValue} and {maxValue}, of {pluralName}:");
                    userResponse = Console.ReadLine();
                    ConsoleUtil.DisplayMessage("");

                    //
                    // input is an Integer
                    //
                    if (int.TryParse(userResponse, out userInteger))
                    {
                        //
                        // input is in range
                        //
                        if (userInteger >= minValue && userInteger <= maxValue)
                        {
                            validInput = true;
                        }
                        //
                        // input is not in range
                        //
                        else
                        {
                            feedbackMessage = $"The number {userInteger} is not in the specified range.";
                        }
                    }
                    //
                    // input is not an Integer
                    //
                    else
                    {
                        feedbackMessage = $"{userResponse} is not an integer.";
                    }

                    if (!validInput && attempts <= maxAttempts)
                    {
                        ConsoleUtil.DisplayMessage($"You entered: {userResponse}");
                        ConsoleUtil.DisplayMessage(feedbackMessage);

                        if (attempts < maxAttempts)
                        {
                            ConsoleUtil.DisplayMessage($"Please enter an integer between {minValue} and {maxValue}.");
                            ConsoleUtil.DisplayMessage("Press any key to try again.");
                            Console.ReadKey();
                        }
                        else
                        {
                            ConsoleUtil.DisplayMessage("It appears you have exceeded the maximum number of attempts allowed.");
                            ConsoleUtil.DisplayMessage("Press any key to continue.");
                            Console.ReadKey();
                        }

                        Console.Clear();
                    }
                    else
                    {
                        ConsoleUtil.DisplayMessage("");
                    }

                    attempts++;
                }
                else
                {
                    maxAttemptsExceeded = true;
                }
            }

            return(validInput);
        }