public string EditProduct() { string userProduct = ""; bool isValidProduct = false; CheckProductResponse productResponse = new CheckProductResponse(); while (isValidProduct == false) { io.DisplayProducts(manager.GetProducts()); userProduct = io.PromptUserForString("Please enter your product type: "); productResponse = manager.CheckProduct(userProduct); if (userProduct == "") { isValidProduct = true; } if (productResponse.Success) { isValidProduct = true; } else { Console.WriteLine("Does not match a product type in our files"); } } return(userProduct); }
public CheckProductResponse CheckForRequestedProduct(string product) { CheckProductResponse response = new CheckProductResponse(); product = product.ToLower(); try { if (_materialRepo.GetMaterials().Any(m => m.ProductType.ToLower() == product)) { response.Success = true; response.Product = _materialRepo.GetMaterials().Single(m => m.ProductType.ToLower() == product); } else { response.Success = false; response.Message = "Error: the product you requested cannot be found in the product repository."; } } catch (Exception e) { response.Success = false; response.Message = "Error: something went wrong with checking the product repository. Contact IT.\n" + $"({e.Message})"; } return(response); }
public void CheckProductTest(string product, bool expected) { CheckProductResponse response = new CheckProductResponse(); response = manager.CheckProduct(product); Assert.AreEqual(response.Success, expected); }
public static void CanCheckRepoForProduct(string product, bool expectedResult) { Manager manager = new Manager(new InMemoryOrderRepo(), new InMemoryMaterialRepo(), new InMemoryTaxRepo()); InMemoryMaterialRepo repo = new InMemoryMaterialRepo(); var productData = repo.GetMaterials(); CheckProductResponse response = manager.CheckForRequestedProduct(product); Assert.AreEqual(expectedResult, response.Success); }
private static Material GetProduct(Manager manager) { bool validProduct = false; Material product = null; while (!validProduct) { Console.Clear(); ConsoleIO.TitleHeader("Add an Order"); Console.WriteLine("(Step 4 of 5)\n"); GetProductsResponse getProductResponse = manager.GetProducts(); if (getProductResponse.Success) { ConsoleIO.PrintProducts(getProductResponse.Materials); } else { Console.WriteLine(getProductResponse.Message); Console.Write("Press any key to continue..."); Console.ReadKey(); } string userProductInput = ConsoleIO.GetProductFromUser(); CheckProductResponse checkProdResponse = manager.CheckForRequestedProduct(userProductInput); if (checkProdResponse.Success == true) { validProduct = true; product = checkProdResponse.Product; } else { Console.Clear(); Console.WriteLine(checkProdResponse.Message); Console.Write("Press any key to retry..."); Console.ReadKey(); } if (validProduct) { validProduct = ConsoleIO.ConsoleKeyConfirmationSwitch($"Entered product is ({userProductInput}).", false); } } return(product); }
public CheckProductResponse CheckProduct(string userProduct) { CheckProductResponse response = new CheckProductResponse(); List <Product> products = _productRepository.LoadFromTxt(); foreach (Product item in products) { if (userProduct.ToUpper() == item.ProductType.ToUpper()) { response.Message = "Success"; response.Success = true; response.product = item; return(response); } else { response.Message = "Invalid entry"; response.Success = false; } } return(response); }
private void CreateCustomerProduct() { bool isValidProduct = false; while (isValidProduct == false) { io.DisplayProducts(manager.GetProducts()); userProduct = io.PromptUserForString("Please enter your product type: "); productResponse = manager.CheckProduct(userProduct); if (productResponse.Success) { isValidProduct = true; } else { Console.WriteLine("Does not match a product type in our files"); } } }
public CheckProductResponse CheckProductTypeEntry(string productType) { CheckProductResponse response = new CheckProductResponse(); List <Products> productList = _productRepository.LoadProducts(); response.ProductTypeToCheck = productType; foreach (var product in productList) { if (product.ProductType == response.ProductTypeToCheck) { response.Success = true; return(response); } else { response.Success = false; response.Message = "Error."; } } return(response); }
private static Material EditProduct(Material oldProduct) { Manager manager = ManagerFactory.Create(); GetProductsResponse productResponse = manager.GetProducts(); Material product = oldProduct; bool validInput = false; string userInput = ""; while (!validInput) { Console.Clear(); ConsoleIO.PrintProducts(productResponse.Materials); Console.Write($"Please choose a product type, or press enter to keep ({oldProduct.ProductType}) as the order material: "); userInput = Console.ReadLine(); if (userInput == "") { validInput = true; } else { CheckProductResponse response = manager.CheckForRequestedProduct(userInput); if (response.Success) { validInput = true; product = response.Product; } else { Console.WriteLine(response.Message); Console.Write("Press any key to retry... "); Console.ReadKey(); } } } return(product); }
public void Execute() { Manager manager = ManagerFactory.Create(); ConsoleIO.Clear(); ConsoleIO.GeneralPrompt("Edit Order"); ConsoleIO.SeperatorBar(); DateTime orderDate = ConsoleIO.RetrieveOrderDateFromUser("Enter an order date (Format: MM/DD/YYYY): "); int orderNumber = ConsoleIO.RetrieveOrderNumberFromUser("Enter an order number: "); OrderResponse originalOrderResponse = manager.RetrieveOrder(orderDate, orderNumber);//ORIGiNAL/UNTOUCHED ORDER!!!!!!!!! //Check for existence of order if (originalOrderResponse.Success) { ConsoleIO.DisplaySingleOrder(originalOrderResponse.Order); } else { ConsoleIO.GeneralPrompt("An error occurred."); ConsoleIO.GeneralPrompt(originalOrderResponse.Message); } //Customer Name ConsoleIO.GeneralPrompt("Enter a new customer name or press enter to continue: "); string updatedCustomerName = Console.ReadLine(); if (string.IsNullOrEmpty(updatedCustomerName)) { updatedCustomerName = originalOrderResponse.Order.CustomerName;//If nothing entered, leave customer name the same } //State string updatedStateAB = ""; while (true) { ConsoleIO.Clear(); ConsoleIO.GeneralPrompt("Available States"); ConsoleIO.SeperatorBar(); ConsoleIO.BlankLine(); DisplayStatesResponse response = new DisplayStatesResponse(); response = manager.DisplayStateList(); if (response.Success) { ConsoleIO.DisplayListOfStates(response.States); } else { ConsoleIO.BlankLine(); ConsoleIO.GeneralPrompt("An error occurred."); ConsoleIO.GeneralPrompt(response.Message); } //Attempted to put in IO, not sure how. Problem: need to return string but one possible user submission is emptry string ConsoleIO.GeneralPrompt("Enter a new state abbreviation OR press enter to continue: "); updatedStateAB = Console.ReadLine().ToUpper(); if (string.IsNullOrEmpty(updatedStateAB)) { updatedStateAB = originalOrderResponse.Order.State; break; } else if (updatedStateAB.Length != 2) { ConsoleIO.GeneralPrompt("Error. State abbreviations must be 2 characters in length."); continue; } StateCheckResponse stateCheckResponse = new StateCheckResponse(); stateCheckResponse = manager.StateCheckAbbreviationEntry(updatedStateAB); if (stateCheckResponse.Success) { break; } else { ConsoleIO.BlankLine(); ConsoleIO.GeneralPrompt("An error occurred."); ConsoleIO.GeneralPrompt(stateCheckResponse.Message); ConsoleIO.GeneralPrompt("Press any key to try again..."); continue; } } //Product Type string updatedProductType = ""; while (true) { ConsoleIO.Clear(); ConsoleIO.GeneralPrompt("Available Products"); ConsoleIO.SeperatorBar(); ConsoleIO.BlankLine(); DisplayProductsResponse response = new DisplayProductsResponse(); response = manager.DisplayProductList(); if (response.Success) { ConsoleIO.DisplayListOfProducts(response.Products); } else { ConsoleIO.BlankLine(); ConsoleIO.GeneralPrompt("An error occurred."); ConsoleIO.GeneralPrompt(response.Message); } ConsoleIO.GeneralPrompt("Enter a new product type (Carpet, Laminate, Tile, Wood) OR press enter to continue: "); updatedProductType = Console.ReadLine(); if (string.IsNullOrEmpty(updatedProductType)) { updatedProductType = originalOrderResponse.Order.ProductType; } CheckProductResponse checkProductResponse = new CheckProductResponse(); checkProductResponse = manager.CheckProductTypeEntry(updatedProductType); if (checkProductResponse.Success) { break; } else { ConsoleIO.BlankLine(); ConsoleIO.GeneralPrompt("An error occurred."); ConsoleIO.GeneralPrompt(checkProductResponse.Message); continue; } } //Area decimal updatedAreaSize; while (true) { ConsoleIO.Clear(); ConsoleIO.GeneralPrompt("Enter a new area size OR press enter to continue: "); string updatedAreaSizeString = Console.ReadLine(); if (string.IsNullOrEmpty(updatedAreaSizeString)) { updatedAreaSizeString = originalOrderResponse.Order.Area.ToString(); updatedAreaSize = decimal.Parse(updatedAreaSizeString); break; } else if (decimal.TryParse(updatedAreaSizeString, out updatedAreaSize) && updatedAreaSize > 99) { ConsoleIO.GeneralPrompt("Area size has been changed."); ConsoleIO.BlankLine(); break; } else { ConsoleIO.BlankLine(); ConsoleIO.GeneralPrompt("An error occurred."); continue; } } ConsoleIO.Clear(); ConsoleIO.GeneralPrompt("Updated Order"); ConsoleIO.SeperatorBar(); //Calculate remaining fields for order Order orderToUpdate = manager.CalculateDisplayUpdateOrder(orderDate, orderNumber, updatedCustomerName, updatedStateAB, updatedProductType, updatedAreaSize); //Display order with changes ConsoleIO.DisplaySingleOrder(orderToUpdate); //Confirm change while (true) { ConsoleIO.GeneralPrompt("Please review the edited order above."); bool updateConfirm = ConsoleIO.Confirmation("Are these edits correct? (Enter Y/N): "); if (updateConfirm == true) { //Call Calculate/Update order AND call repo to change manager.UpdateOrder(orderDate, orderNumber, updatedCustomerName, updatedStateAB, updatedProductType, updatedAreaSize); ConsoleIO.GeneralPrompt("Order edit successful."); break; } else { ConsoleIO.GeneralPrompt("Order edit cancelled."); break; } } ConsoleIO.ReadKeyPlusPrompt("Press any key to continue..."); }
//Questions/Concerns //================================= //Order Confirmation - Do I need a response object in case order creation in manager fails? //--If so, what to catch? public void Execute() { Manager manager = ManagerFactory.Create(); string productType = ""; string stateAbbreviation = ""; ConsoleIO.Clear(); ConsoleIO.GeneralPrompt("Add Order"); ConsoleIO.SeperatorBar(); DateTime orderDate = ConsoleIO.RetrieveOrderDateFromUser("Enter an order date (Format: MM/DD/YYYY): "); ConsoleIO.BlankLine(); string customerName = ConsoleIO.RetrieveCustomerNameFromUser("Enter a customer name: "); while (true) { ConsoleIO.Clear(); ConsoleIO.GeneralPrompt("Available States"); ConsoleIO.SeperatorBar(); ConsoleIO.BlankLine(); DisplayStatesResponse response = manager.DisplayStateList(); if (response.Success) { ConsoleIO.DisplayListOfStates(response.States); } else { ConsoleIO.BlankLine(); ConsoleIO.GeneralPrompt("An error occurred."); ConsoleIO.GeneralPrompt(response.Message); } stateAbbreviation = ConsoleIO.RetrieveStateAbbreviationFromUser("Enter a state abbreviation (Example: PA): "); StateCheckResponse stateCheckResponse = manager.StateCheckAbbreviationEntry(stateAbbreviation); if (stateCheckResponse.Success) { break; } else { ConsoleIO.BlankLine(); ConsoleIO.GeneralPrompt("An error occurred."); ConsoleIO.GeneralPrompt(stateCheckResponse.Message); ConsoleIO.ReadKeyPlusPrompt("Press any key to try again..."); } } //Product Type while (true) { ConsoleIO.Clear(); ConsoleIO.GeneralPrompt("Available Products"); ConsoleIO.SeperatorBar(); ConsoleIO.BlankLine(); DisplayProductsResponse response = manager.DisplayProductList(); if (response.Success) { ConsoleIO.DisplayListOfProducts(response.Products); } else { ConsoleIO.BlankLine(); ConsoleIO.GeneralPrompt("An error occurred."); ConsoleIO.GeneralPrompt(response.Message); } ConsoleIO.GeneralPrompt("Enter a Product Type (Carpet, Laminate, Tile, Wood)"); ConsoleIO.BlankLine(); productType = ConsoleIO.RetrieveProductTypeFromUser("(WARNING: Case Sensitive Entry): "); CheckProductResponse checkProductResponse = manager.CheckProductTypeEntry(productType); if (checkProductResponse.Success) { break; } else { ConsoleIO.BlankLine(); ConsoleIO.GeneralPrompt("An error occurred."); ConsoleIO.GeneralPrompt(checkProductResponse.Message); continue; } } //Area ConsoleIO.BlankLine(); decimal area = ConsoleIO.RetrieveAreaSizeFromUser("Enter an area size (Minimum Amount = 100): "); //Display Order ConsoleIO.Clear(); ConsoleIO.GeneralPrompt("Here is your order:"); ConsoleIO.BlankLine(); Order orderToCreate = manager.CreateNewOrder(orderDate, customerName, stateAbbreviation, productType, area); ConsoleIO.DisplaySingleOrder(orderToCreate); //Confirm Add Order ConsoleIO.GeneralPrompt("Order Confirmation"); ConsoleIO.SeperatorBar(); bool addOrderConfirmation = ConsoleIO.Confirmation("Are you sure you would like to create the above order? (Enter Y/N): "); if (addOrderConfirmation == true) { manager.AddOrder(orderToCreate); ConsoleIO.BlankLine(); ConsoleIO.GeneralPrompt("Your order has been added to the system."); } else { ConsoleIO.GeneralPrompt("Order Creation Canceled."); ConsoleIO.BlankLine(); } ConsoleIO.ReadKeyPlusPrompt("Press any key to continue..."); }