private string GetEditOrderProductType(OperationsManager manager, OrderLookupResponse response) { bool isCorrectProductType = false; string productInputString = ""; do { Console.Clear(); Console.WriteLine(pageHeader); Console.WriteLine("\n***Edit Order Number {0} for {1}/{2}/{3}***", response.Order.OrderNumber, _orderDate.Substring(0, 2), _orderDate.Substring(2, 2), _orderDate.Substring(4, 4)); Console.WriteLine("\nIf you wish to edit a field, type in the new information. If you wish to leave the field unchanged, simply press enter."); Console.WriteLine("\nCustomer Name ({0}): {1}", response.Order.CustomerName, nameInput); Console.WriteLine("State ({0}): {1}", response.Order.State, stateInput); Console.WriteLine("ProductType ({0}): ", response.Order.ProductType); Console.WriteLine(); IProductRepository productRepo = RepoFactory.CreateProductRepo(); List <Product> products = productRepo.GetListOfProducts(); int listNumber = 1; foreach (var product in products) { Console.WriteLine("\t" + listNumber + ". " + product.ProductType); listNumber++; } Console.Write("\nEnter selection: "); string userInput = Console.ReadLine(); int j; if (!int.TryParse(userInput, out j) || j < 1 || j > listNumber - 1) { Console.Write($"\nPlease enter a valid number (1-{listNumber - 1}). " + ConsoleIO.anyKey); Console.ReadKey(); isCorrectProductType = false; } else { productInputString = products[j - 1].ProductType; isCorrectProductType = true; } } while (!isCorrectProductType); return(productInputString); }
private string GetOrderProductType(OperationsManager manager) { bool isValidProductType = false; string productInputString = ""; do { Console.Clear(); Console.WriteLine(pageHeader); Console.WriteLine(); Console.WriteLine(promptForOrderDetails); Console.WriteLine("\nCustomer name: " + _customerName); Console.WriteLine("State (2-letter abbreviation): " + _stateAbbreviation); Console.WriteLine("\nSelect Product Type:\n"); IProductRepository productRepo = RepoFactory.CreateProductRepo(); List <Product> products = productRepo.GetListOfProducts(); int listNumber = 1; foreach (var product in products) { Console.WriteLine("\t" + listNumber + ". " + product.ProductType); listNumber++; } Console.Write("\nEnter selection: "); string productInput = Console.ReadLine(); int j; while (!int.TryParse(productInput, out j) || j < 1 || j > listNumber - 1) { Console.Write("\nPlease enter a valid number (1-{0}): ", listNumber - 1); productInput = Console.ReadLine(); } productInputString = products[j - 1].ProductType; isValidProductType = true; } while (!isValidProductType); return(productInputString); }
public AddOrderResponse CheckProduct(string productType) { AddOrderResponse response = new AddOrderResponse(); IProductRepository stateRepo = RepoFactory.CreateProductRepo(); List <Product> products = stateRepo.GetListOfProducts(); foreach (var product in products) { if (product.ProductType == productType) { response.Success = true; return(response); } } response.Success = false; response.Message = $"We do not sell product type \"{productType}\"."; return(response); }