public void NewProduct(Order order) { OrderManager manager = OrderManagerFactory.Create(); while (!isValid) { ProductRepo repo = new ProductRepo(); string productType = ConsoleIO.GetProduct(repo.LoadProducts()); Console.WriteLine($"Is this the correct new product: {productType}, Y/N?"); string correctProduct = Console.ReadLine().ToUpper(); if (correctProduct == "Y") { isValid = true; } ProductTypeResponse response = manager.FindProductByType(productType); if (response.Success) { manager.SaveCurrentOrder(order); ConsoleIO.DisplayEditedOrderDetail(order); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } else { response.Success = false; response.Message = "An error occurred"; Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } } }
public string EditProductType() { bool isValid = false; ProductTypeResponse response = new ProductTypeResponse(); string userType = ""; //display options io.DisplayProducts(manager.ProductList()); while (isValid == false) { userType = io.GetStringFromUser("Please select product type or press enter to skip: "); if (userType == "") { return(userType); } //check if this product is an option on list response = manager.ProductType(userType); if (response.Success) { isValid = true; } else { Console.WriteLine("The selected product type is not available."); } } return(response.Product.ProductType); }
public void ProductTypeTest(string type, bool expected) { ProductTypeResponse actual = new ProductTypeResponse(); List <Product> products = manager.ProductList(); actual = manager.ProductType(type); Assert.AreEqual(expected, actual.Success); }
public void GetProductTest(string productType, decimal costPerSquareFoot, decimal laborCost) { MockProductRepo productRepo = new MockProductRepo(); ProductTypeResponse response = new ProductTypeResponse(); var result = productRepo.FindProductType(productType); Assert.IsNotNull(result); Assert.AreEqual(productType, result.ProductType); }
public ProductTypeResponse ProductType(string type) { ProductTypeResponse response = new ProductTypeResponse(); foreach (var item in products) { if (type.ToUpper() == item.ProductType.ToUpper()) { response.Message = "Product type available."; response.Success = true; response.Product = item; return(response); } else { response.Message = "Not a valid product type."; response.Success = false; } } return(response); }
private void NewOrderProduct() { bool isValidProduct = false; while (isValidProduct == false) //add ignore case in validation { //display product options io.DisplayProducts(manager.ProductList()); //get product type string and check list for match string userType = io.GetStringFromUser("Please select product type: "); productResponse = manager.ProductType(userType); if (productResponse.Success) { isValidProduct = true; } else { Console.WriteLine("The selected product type is not available."); } } }
internal void Execute() { bool isValid = false; OrderManager manager = OrderManagerFactory.Create(); SaveNewOrderRequest saveRequest = new SaveNewOrderRequest(); saveRequest.Order = new Order(); Console.Clear(); Console.WriteLine("ADD A NEW ORDER"); Console.WriteLine("****************************"); Console.WriteLine(); Console.WriteLine("NEW ORDERS MUST BE FUTURE DATED!"); while (!isValid) { Console.WriteLine(); DateTime orderDate = ConsoleIO.GetDate(); Console.WriteLine(); if (orderDate > DateTime.Today) { saveRequest.Order.OrderDate = orderDate; isValid = true; } else { Console.WriteLine("The new order must be futured dated."); } } //Cannot be blank. Allowed to contain [a-z][0-9] string userInput = ConsoleIO.GetUserName(); Console.WriteLine(); saveRequest.Order.CustomerName = userInput; //State must be checked against the tax file. bool validState = false; while (!validState) { string stateInput = ConsoleIO.GetStateName(); Console.WriteLine(); GetStateResponse stateResponse = manager.GetStateTaxData(stateInput); if (stateResponse.Success) { saveRequest.Order.StateTaxData = stateResponse.TaxData; validState = true; } else { stateResponse.Success = false; Console.WriteLine("That state does not exist!"); } } //verify that is the correct product type bool validProduct = false; while (!validProduct) { ProductRepo repo = new ProductRepo(); string productType = ConsoleIO.GetProduct(repo.LoadProducts()); Console.WriteLine(); ProductTypeResponse productResponse = manager.FindProductByType(productType); if (productResponse.Success) { saveRequest.Order.ProductDetail = productResponse.ProductType; validProduct = true; } else { productResponse.Success = false; Console.WriteLine("That product does not exist!"); //Console.WriteLine(productResponse.Message); } } string areaInput = ConsoleIO.GetArea(); saveRequest.Order.Area = decimal.Parse(areaInput); Console.WriteLine("Would you like to save this order?: Y/N"); string saveResponse = Console.ReadLine().ToUpper(); if (saveResponse == "Y") { manager.SaveNewOrder(saveRequest.Order); } else { Console.WriteLine("Press any key to return to Menu"); Console.ReadKey(); Menu.Start(); } }