Esempio n. 1
0
        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 difficulty. You will return to the main menu.");
                return(false);
            }
            else
            {
                return(userResponse == "YES" ? true : false);
            }
        }
Esempio n. 2
0
        public int DisplayGetNumberOfUnitsToSell(Product product)
        {
            ConsoleUtil.HeaderText = "Sell Inventory";
            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage("Selling " + product.Type.ToString() + " products.");
            ConsoleUtil.DisplayMessage("");

            if (!ConsoleValidator.TryGetIntegerFromUser(MINIMUM_BUYSELL_AMOUNT, MAXIMUM_BUYSELL_AMOUNT, MAXIMUM_ATTEMPTS, "products", out int numberOfUnitsToSell))
            {
                ConsoleUtil.DisplayMessage("It appears you are having difficulty setting the number of products to sell.");
                ConsoleUtil.DisplayMessage("By default, the number of products to sell will be set to zero.");
                numberOfUnitsToSell = 0;
                DisplayContinuePrompt();
            }

            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage(numberOfUnitsToSell + " " + product.Type.ToString() + " products have been subtracted from the inventory.");

            DisplayContinuePrompt();

            return(numberOfUnitsToSell);
        }
        /// <summary>
        /// Edits the salesperson's account information
        /// </summary>
        /// <param name="salesperson"></param>
        public void DisplayEditAccountInfo(Salesperson salesperson)
        {
            bool   validResponse = false;
            int    userAge       = 0;
            string userResponse;

            Salesperson.Ranks rank;
            //
            // set up the console
            //
            ConsoleUtil.HeaderText = "Account Editing";
            ConsoleUtil.DisplayReset();

            //
            // get new account info
            //
            ConsoleUtil.DisplayMessage("Just press enter if you wish to skip the current field");
            ConsoleUtil.DisplayMessage("");

            ConsoleUtil.DisplayMessage($"First Name: {salesperson.FirstName}");

            userResponse = Console.ReadLine();
            if (userResponse != "")
            {
                salesperson.FirstName = userResponse;
            }

            Console.WriteLine("");

            ConsoleUtil.DisplayMessage($"Last Name: {salesperson.LastName}");

            userResponse = Console.ReadLine();
            if (userResponse != "")
            {
                salesperson.LastName = userResponse;
            }

            Console.WriteLine("");


            ConsoleUtil.DisplayMessage($"Age: {salesperson.Age}");

            validResponse = ConsoleValidator.TryGetIntegerFromUser(10, 90, MAXIMUM_ATTEMPTS, "years old", out userAge, true);
            if (validResponse)
            {
                salesperson.Age = userAge;
            }

            ConsoleUtil.DisplayMessage($"Account ID: {salesperson.AccountID}");

            if (userResponse != "")
            {
                salesperson.AccountID = userResponse;
            }
            Console.WriteLine("");


            ConsoleUtil.DisplayMessage($"Rank: {salesperson.Rank}");

            if (ConsoleValidator.GetEnumValueFromUser <Salesperson.Ranks>(MAXIMUM_ATTEMPTS, "Rank:", out rank, true))
            {
                salesperson.Rank = rank;
            }

            DisplayContinuePrompt();
        }
        /// <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()
        {
            //
            // initialize variables
            //
            bool validResponse;
            int  userAge;
            int  productAmount;

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

            //
            // set up the console
            //
            ConsoleUtil.HeaderText = "Account Setup";
            ConsoleUtil.DisplayReset();

            //
            // get new account info
            //
            ConsoleUtil.DisplayPromptMessage("First name: ");
            salesperson.FirstName = Console.ReadLine();
            Console.WriteLine("");

            ConsoleUtil.DisplayPromptMessage("Last name: ");
            salesperson.LastName = Console.ReadLine();
            Console.WriteLine("");

            ConsoleUtil.DisplayMessage("Age");
            validResponse = ConsoleValidator.TryGetIntegerFromUser(10, 90, MAXIMUM_ATTEMPTS, "years old", out userAge);
            if (validResponse)
            {
                salesperson.Age = userAge;
            }

            ConsoleUtil.DisplayPromptMessage("Account ID: ");
            salesperson.AccountID = Console.ReadLine();
            Console.WriteLine("");

            //
            // validate user input
            //
            ConsoleUtil.DisplayMessage("Setting up inventory..");
            ConsoleUtil.DisplayMessage("");
            if (!ConsoleValidator.GetEnumValueFromUser <Product.ProductType>(MAXIMUM_ATTEMPTS, "Body Style:", out productType))
            {
                ConsoleUtil.DisplayMessage("Maximum attempts exceeded, returning to main menu.");
            }


            if (!ConsoleValidator.TryGetIntegerFromUser(MINIMUM_BUYSELL_AMOUNT, MAXIMUM_BUYSELL_AMOUNT, MAXIMUM_ATTEMPTS, $"{productType.ToString()}s", out productAmount))
            {
                ConsoleUtil.DisplayMessage("Max attempts exceeded, returning to main menu with default value of 0 vehicles.");
            }

            //
            // set salesman product object
            //
            salesperson.CurrentStock[productType].NumberOfUnits = productAmount;

            salesperson.Rank = Salesperson.Ranks.Beginner;

            DisplayContinuePrompt();
            return(salesperson);
        }
Esempio n. 5
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();

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

            ConsoleUtil.DisplayMessage("Setup your account now.");
            ConsoleUtil.DisplayMessage("");

            ConsoleUtil.DisplayPromptMessage("Enter your first name: ");
            salesperson.FirstName = Console.ReadLine();
            ConsoleUtil.DisplayMessage("");

            ConsoleUtil.DisplayPromptMessage("Enter your last name: ");
            salesperson.LastName = Console.ReadLine();
            ConsoleUtil.DisplayMessage("");

            ConsoleUtil.DisplayPromptMessage("Enter your account ID: ");
            salesperson.AccountID = Console.ReadLine();
            ConsoleUtil.DisplayMessage("");

            ConsoleUtil.DisplayPromptMessage("Product Types: ");
            ConsoleUtil.DisplayMessage("");

            foreach (string productTypeName in Enum.GetNames(typeof(ProductType)))
            {
                if (productTypeName != ProductType.None.ToString())
                {
                    ConsoleUtil.DisplayMessage(productTypeName);
                }
            }

            ConsoleUtil.DisplayMessage("");
            ConsoleUtil.DisplayPromptMessage("Enter the product type: ");
            ProductType productType;

            if (Enum.TryParse <ProductType>(UppercaseFirst(Console.ReadLine()), out productType))
            {
                salesperson.CurrentStock.Type = productType;
            }
            else
            {
                salesperson.CurrentStock.Type = ProductType.None;
            }

            if (ConsoleValidator.TryGetIntegerFromUser(0, 100, 3, "products", out int numberOfUnits))
            {
                salesperson.CurrentStock.AddProducts(numberOfUnits);
            }
            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 zero.");
                salesperson.CurrentStock.AddProducts(0);
                DisplayContinuePrompt();
            }

            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage("Your account is setup");

            DisplayContinuePrompt();

            return(salesperson);
        }