public Product DisplayGetNumberOfUnitsToSell(List <Product> products) { Product.ProductType productType; ConsoleUtil.HeaderText = "Sell Inventory"; ConsoleUtil.DisplayReset(); productType = ListProducts(products); // // Get number of products to sell. // ConsoleUtil.DisplayMessage("Selling " + UnderscoreToSpace(productType.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 pruducts to sell will be set to zero."); numberOfUnitsToSell = 0; DisplayContinuePrompt(); } ConsoleUtil.DisplayReset(); ConsoleUtil.DisplayMessage(numberOfUnitsToSell + " " + UnderscoreToSpace(productType.ToString()) + (numberOfUnitsToSell > 1 && productType.ToString().Last() != 's' ? "s" : "") + " have been subtracted from the inventory."); DisplayContinuePrompt(); return(new Product(productType, numberOfUnitsToSell, false)); }
public bool DisplaySaveAccountInfo(Salesperson salesperson, out bool maxAttemptsExceeded) { string userResponse; maxAttemptsExceeded = false; ConsoleUtil.HeaderText = "Save Account"; ConsoleUtil.DisplayReset(); ConsoleUtil.DisplayMessage("The current account information."); DisplayAccountInfo(salesperson, false); 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 { // // Note use of ternary operator. // return(userResponse.ToLower() == "yes" ? true : false); } }
/// <summary> /// get the number of product units to sell from the user /// </summary> /// <returns>int number of units to buy</returns> public int DisplayGetNumberOfUnitsToSell(Product product) { ConsoleUtil.HeaderText = "Sell Inventory"; ConsoleUtil.DisplayReset(); // // get number of products to sell // ConsoleUtil.DisplayMessage("Selling " + product.Type.ToString() + " products."); ConsoleUtil.DisplayMessage(""); if (!ConsoleValidator.TryGetIntegerFromUser(0, 100, 3, "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); }
public Product DisplayGetNumberOfUnitsToBuy(List <Product> products) { Product.ProductType productType; ConsoleUtil.HeaderText = "Buy Inventory"; ConsoleUtil.DisplayReset(); productType = ListProducts(products); // // get number of products to buy // ConsoleUtil.DisplayMessage("Buying " + UnderscoreToSpace(productType.ToString()) + " products."); ConsoleUtil.DisplayMessage(""); if (!ConsoleValidator.TryGetIntegerFromUser(MINIMUM_BUYSELL_AMOUNT, MAXIMUM_BUYSELL_AMOUNT, MAXIMUM_ATTEMPTS, "products", out int numberOfUnitsToBuy)) { ConsoleUtil.DisplayMessage("It appears you are having difficulty setting the number of products to buy."); ConsoleUtil.DisplayMessage("By default, the number of products to sell will be set to zero."); numberOfUnitsToBuy = 0; DisplayContinuePrompt(); } ConsoleUtil.DisplayReset(); ConsoleUtil.DisplayMessage(numberOfUnitsToBuy + " " + UnderscoreToSpace(productType.ToString()) + " products have been added to the inventory."); DisplayContinuePrompt(); return(new Product(productType, numberOfUnitsToBuy, false)); }
/// <summary> /// queries user to load account information /// </summary> /// <param name="salesperson">Salesperson object</param> /// <param name="maxAttemptsExceeded">maximum attempts exceeded flag</param> /// <returns>user choice</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> /// get the number of product units to buy from the user /// </summary> /// <returns>int number of units to buy</returns> public int DisplayGetNumberOfUnitsToBuy(Product product) { ConsoleUtil.HeaderText = "Buy Inventory"; ConsoleUtil.DisplayReset(); int numberOfUnitsToBuy; // // get number of products to buy // ConsoleUtil.DisplayMessage("Buying " + product.Type.ToString() + " products."); ConsoleUtil.DisplayMessage(""); if (!ConsoleValidator.TryGetIntegerFromUser(MINIMUM_BUYSELL_AMOUNT, MAXIMUM_BUYSELL_AMOUNT, MAXIMUM_ATTEMPTS, "products", out numberOfUnitsToBuy)) { ConsoleUtil.DisplayMessage("It appears you are having difficulty setting the number of products to buy."); ConsoleUtil.DisplayMessage("By default, the number of products to sell will be set to zero."); numberOfUnitsToBuy = 0; DisplayContinuePrompt(); } ConsoleUtil.DisplayReset(); ConsoleUtil.DisplayMessage(numberOfUnitsToBuy + " " + product.Type.ToString() + " products have been added to the inventory."); DisplayContinuePrompt(); return(numberOfUnitsToBuy); }
public int DisplayGetNumberOfUnitsToBuy(Product product) { ConsoleUtil.HeaderText = "Buy Inventory"; ConsoleUtil.DisplayReset(); ConsoleUtil.DisplayMessage("Buying " + product.Type.ToString() + " products."); ConsoleUtil.DisplayMessage(""); // validate get number of units from user if (!ConsoleValidator.TryGetIntegerFromUser(MINIMUM_BUYSELL_AMOUNT, MAXIMUM_BUYSELL_AMOUNT, MAXIMUM_ATTEMPTS, "Product", out int numberOfUnitsToBuy)) { ConsoleUtil.DisplayMessage("It appears you are having difficulties setting the number of units to buy."); ConsoleUtil.DisplayMessage("The number of units to buy will be set to it's default value of 0."); numberOfUnitsToBuy = 0; DisplayContinuePrompt(); } ConsoleUtil.DisplayReset(); ConsoleUtil.DisplayMessage(numberOfUnitsToBuy + " products of " + product.Type.ToString() + " have been added to the inventory."); DisplayContinuePrompt(); return(numberOfUnitsToBuy); }
public Salesperson DisplayUpdateAccountInfo(Salesperson _salesperson) { ConsoleUtil.HeaderText = "Updating Account Info"; ConsoleUtil.DisplayReset(); //ConsoleKeyInfo userResponse = Console.ReadKey(); ConsoleUtil.DisplayMessage("Re-enter a value if you must update. If the info doesn't have to be changed," + "\nsimply press the Enter key.\n"); Console.WriteLine(); Console.Write($"Current first name: {_salesperson.FirstName}. New first name: "); ConsoleKeyInfo userResponse = Console.ReadKey(); if (userResponse.Key != ConsoleKey.Enter) { _salesperson.FirstName = userResponse.Key.ToString() + Console.ReadLine(); } Console.WriteLine(); Console.Write($"Current last name: {_salesperson.LastName}. New last name: "); userResponse = Console.ReadKey(); if (userResponse.Key != ConsoleKey.Enter) { _salesperson.LastName = userResponse.Key.ToString() + Console.ReadLine(); } Console.WriteLine(); Console.Write($"Current account ID: {_salesperson.AccountID}. New account ID: "); userResponse = Console.ReadKey(); if (userResponse.Key != ConsoleKey.Enter) { _salesperson.AccountID = userResponse.Key.ToString() + Console.ReadLine(); } { if (ConsoleValidator.TryGetIntegerFromUser(18, 100, 3, "your age", out int userInteger)) { Console.WriteLine("Incorrect answer, you must be old. Age set to 100."); _salesperson.Age = 100; } _salesperson.Age = userInteger; } return(_salesperson); }
/// <summary> /// get the number of units to sell from the user /// </summary> /// <param name="_salesperson"></param> /// <returns></returns> public int DisplayGetNumberOfUnitsToSell(Salesperson _salesperson) { ConsoleUtil.HeaderText = "Sell Inventory"; ConsoleUtil.DisplayReset(); if (!ConsoleValidator.TryGetIntegerFromUser(0, 100, 3, "products", out int numberOfUnitsToSell)) { ConsoleUtil.DisplayMessage("You are entering invalid numbers of products to sell."); ConsoleUtil.DisplayMessage("We will sell 0 products."); numberOfUnitsToSell = 0; DisplayContinuePrompt(); } ConsoleUtil.DisplayReset(); ConsoleUtil.DisplayMessage("You have sold " + numberOfUnitsToSell + " " + _salesperson.Inventory.Type.ToString() + " units"); DisplayContinuePrompt(); return(numberOfUnitsToSell); }
public bool DisplayLoadAccountInfo(Salesperson _salesperson, out bool maxAttemptsExceeded) { maxAttemptsExceeded = false; string userResponse; ConsoleUtil.HeaderText = "Load Account"; ConsoleUtil.DisplayReset(); ConsoleUtil.DisplayMessage(""); userResponse = ConsoleValidator.GetYesNoFromUser(maxAttempts, "Load account info?", out maxAttemptsExceeded); if (maxAttemptsExceeded) { ConsoleUtil.DisplayMessage("It appears you are having difficult, we will return you" + "to the main menu"); } else { return(userResponse == "yes" ? true : false); } return(maxAttemptsExceeded); }
/// <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.DisplayPromptMessage("First Name: "); _salesperson.FirstName = UppercaseFirst(Console.ReadLine()); ConsoleUtil.DisplayPromptMessage("Last Name: "); _salesperson.LastName = UppercaseFirst(Console.ReadLine()); ConsoleUtil.DisplayPromptMessage("Account ID: "); _salesperson.AccountID = Console.ReadLine(); if (!ConsoleValidator.TryGetIntegerFromUser(18, 100, 3, "Age", out int userInteger)) { Console.WriteLine("Looks like you are having trouble with your age. Clearly you are old as dirt, setting age to 100."); _salesperson.Age = 100; } _salesperson.Age = userInteger; string userResponse = ConsoleValidator.GetYesNoFromUser(3, "Are you a hockey fan?", out bool maxAttemptsExceeded); if (maxAttemptsExceeded) { Console.WriteLine("Not valid answer. You must not be a hockey fan."); } if (userResponse == "yes") { _salesperson.IsHockeyFan = true; } else { _salesperson.IsHockeyFan = false; } ConsoleUtil.DisplayMessage("Product Types"); ConsoleUtil.DisplayMessage(""); // // list all product types // foreach (string productTypeName in Enum.GetNames(typeof(Product.ProductType))) { // // do not display the "NONE" enum value // if (productTypeName != Product.ProductType.None.ToString()) { ConsoleUtil.DisplayMessage(productTypeName); } } // // get product type, if invalid entry, set type to "None" // ConsoleUtil.DisplayMessage(""); ConsoleUtil.DisplayPromptMessage("Enter the product type: "); Product.ProductType productType; if (Enum.TryParse <Product.ProductType>(UppercaseFirst(Console.ReadLine()), out productType)) { _salesperson.Inventory.Type = productType; } else { _salesperson.Inventory.Type = Product.ProductType.None; } if (ConsoleValidator.TryGetIntegerFromUser(0, 100, 3, "units", out int numberOfUnits)) { _salesperson.Inventory.AddProducts(numberOfUnits); } else { ConsoleUtil.DisplayMessage("You did not enter a valid number of units."); ConsoleUtil.DisplayMessage("We will set your intentory to 0"); } _salesperson.Inventory.NumberOfUnits = numberOfUnits; ConsoleUtil.DisplayReset(); ConsoleUtil.DisplayMessage("Your account is now setup"); return(_salesperson); }
public void DisplayAddInventory(Salesperson salesperson) { Product.ProductType productType; string errorMes = "It appears you have selected an incorrect choice."; ConsoleUtil.HeaderText = "Add Inventory"; ConsoleUtil.DisplayReset(); ConsoleUtil.DisplayMessage("Select the product you'd like to add."); ConsoleUtil.DisplayMessage(""); while (true) { ConsoleUtil.DisplayMessage("Product Types:"); ConsoleUtil.DisplayMessage(""); // // list all product types // for (int i = 1; i < Enum.GetNames(typeof(Product.ProductType)).Length; i++) { Console.WriteLine("\t " + i + ". " + UnderscoreToSpace(Enum.GetName(typeof(Product.ProductType), i))); } // // get product type, if invalid entry ask user to choose again. // ConsoleUtil.DisplayMessage(""); ConsoleUtil.DisplayPromptMessage("Select a product type. (1 - " + (Enum.GetNames(typeof(Product.ProductType)).Length - 1) + "): "); ConsoleKeyInfo userResponse = Console.ReadKey(true); ConsoleUtil.DisplayMessage(""); if (Enum.TryParse <Product.ProductType>(userResponse.KeyChar.ToString(), out productType)) { if (salesperson.CurrentStock.Exists(x => x.Type == productType)) { errorMes = UnderscoreToSpace(productType.ToString()) + " is already in your inventory try a different item."; } else { ConsoleUtil.DisplayMessage("You've selected " + UnderscoreToSpace(productType.ToString()) + "."); break; } } ConsoleUtil.DisplayReset(); ConsoleUtil.DisplayMessage( errorMes + Environment.NewLine + "Press any key to continue or the ESC key to quit the application."); } ConsoleUtil.DisplayMessage(""); // // get number of products in inventory // if (ConsoleValidator.TryGetIntegerFromUser(MINIMUM_BUYSELL_AMOUNT, MAXIMUM_BUYSELL_AMOUNT, MAXIMUM_ATTEMPTS, "products", out int numberOfUnits)) { salesperson.CurrentStock.Add(new Product(productType, numberOfUnits, false)); } 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.Add(new Product(productType, 0, false)); } salesperson.Logs.Push(DateTime.Now + " ... " + numberOfUnits + " " + productType + " added to inventory!"); }
/// <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.DisplayMessage("Product Types"); ConsoleUtil.DisplayMessage(""); // // list all product types // foreach (string productTypeName in Enum.GetNames(typeof(Product.ProductType))) { // // do not display the "None" enum value // if (productTypeName != Product.ProductType.None.ToString()) { ConsoleUtil.DisplayMessage(productTypeName); } } // // get product type, if invalid entry, set type to "None" // ConsoleUtil.DisplayMessage(""); ConsoleUtil.DisplayPromptMessage("Enter the product type: "); Product.ProductType productType; if (Enum.TryParse <Product.ProductType>(UppercaseFirst(Console.ReadLine()), out productType)) { salesperson.CurrentStock.Type = productType; } else { salesperson.CurrentStock.Type = Product.ProductType.None; } // // get number of products in inventory // 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.DisplayMessage(""); ConsoleUtil.DisplayReset(); ConsoleUtil.DisplayMessage("Your account is setup"); DisplayContinuePrompt(); return(salesperson); }
/// <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.DisplayMessage("Product Types: "); ConsoleUtil.DisplayMessage(""); // list all types of products available // Enum.GetNames retrieves an array of the names in ProductType foreach (string productName in Enum.GetNames(typeof(Product.ProductType))) { // do not display "None" product type if (productName != "None") { ConsoleUtil.DisplayMessage(productName); } } // get product type from user, if input is invalid: product type will be set to "None" ConsoleUtil.DisplayMessage(""); ConsoleUtil.DisplayPromptMessage("Enter product: "); // new variable for product type //Product.ProductType productType; if (Enum.TryParse <Product.ProductType>(UppercaseFirst(Console.ReadLine()), out Product.ProductType productType)) { // set type of current stock to selected product type salesperson.CurrentStock.Type = productType; } else { // sets type of current stock to "none" product type salesperson.CurrentStock.Type = Product.ProductType.None; } // get number of products if (ConsoleValidator.TryGetIntegerFromUser(MINIMUM_BUYSELL_AMOUNT, MAXIMUM_BUYSELL_AMOUNT, MAXIMUM_ATTEMPTS, "products", out int numberOfUnits)) { // add products to current stock 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 0."); salesperson.CurrentStock.AddProducts(0); DisplayContinuePrompt(); } ConsoleUtil.DisplayReset(); ConsoleUtil.DisplayMessage("Your account is setup"); ConsoleUtil.DisplayMessage(numberOfUnits + " units of " + productType + " have been added to your inventory."); DisplayContinuePrompt(); return(salesperson); }