/// <summary>
        /// prompts the user to save account and travel log
        /// </summary>
        /// <param name="salesperson"></param>
        /// <param name="maxAttemptsExceeded"></param>
        /// <returns></returns>
        public bool DisplaySaveAccountInfo(Salesperson salesperson, out bool maxAttemptsExceeded)
        {
            string userResponse;

            maxAttemptsExceeded = false;

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

            ConsoleUtil.DisplayMessage("The current account information.");
            DisplayAccountDetail(salesperson);

            ConsoleUtil.DisplayMessage("");
            userResponse = ConsoleValidator.GetYesNoFromUser(MAXIMUM_ATTEMPTS, "Save 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);
            }
        }
Beispiel #2
0
        /// <summary>
        /// display confirmation that a salesperson account was successfully loaded
        /// </summary>
        /// <param name="maxAttemptsExceeded"></param>
        /// <returns>bool</returns>
        public bool DisplayLoadAccountInfo(out bool maxAttemptsExceeded)
        {
            string userResponse;

            maxAttemptsExceeded = false;

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

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

            if (maxAttemptsExceeded)
            {
                ConsoleUtil.DisplayMessage("It appears you are having difficulty.  You will " +
                                           "return to the main menu.");
                return(false);
            }
            else
            {
                //
                // note use of ternary operator
                //
                return(userResponse == "YES" ? true : false);
            }
        }
        /// <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);
        }