public void Execute() { OrderManager manager = OrderManagerFactory.Create(); DateTime date = UserIO.GetDateFromUser("Enter the date the order was placed (example \"MM-DD-YYYY\"):"); DisplayOrderResponse response = manager.OrderLookup(date); Console.Clear(); if (response.Success) { Order order = null; while (order == null) { ConsoleIO.DisplayOrderDetails(response.Order, response.Date); order = UserIO.GetOrderFromUser("Which order would you like to edit? (Use Order ID) :", response.Order); if (order == null) { Console.WriteLine("The input did not match an order ID"); } else { break; } } while (true) { string customerName = UserIO.GetStringFromUserCanBeNull($"Please enter a new name for the customer. The current customer name is {order.CustomerName}. If you do no wish to change this field hit enter without entering any data. :"); if (customerName.Trim() == string.Empty) { break; } bool result = order.CustomerName.All(c => Char.IsLetterOrDigit(c) || c == '.' || c == ',' || c == ' '); if (result == false) { Console.WriteLine("The customer name you entered contained an invalid value"); Console.ReadLine(); } else { order.CustomerName = customerName; break; } } Console.Clear(); TaxesRepository taxRepo = new TaxesRepository(); ConsoleIO.DisplayTaxRepo(taxRepo.List()); Taxes tax = null; while (tax == null) { string state = UserIO.GetStringFromUserCanBeNull($"Please enter the new state Abbreviation for the customer. The current state is {order.State}.If you do no wish to change this field hit enter without entering any data. :").ToUpper(); if (state != string.Empty) { tax = taxRepo.List().FirstOrDefault(t => t.StateAbbreviation.ToUpper() == state); if (tax != null) { order.State = tax.StateAbbreviation; order.TaxRate = tax.TaxRate; break; } else { Console.WriteLine("We do not do business in that state"); Console.WriteLine("Press any key to try again..."); Console.ReadLine(); } } else { break; } } Console.Clear(); ProductRepository productRepo = new ProductRepository(); ConsoleIO.DisplayProductRepo(productRepo.List()); Product product = null; while (product == null) { string productType = UserIO.GetStringFromUserCanBeNull($"Please enter the new product type information for the customer. The current product type is {order.ProductType} (Carpet, Laminate, Tile, Wood). If you do no wish to change this field hit enter without entering any data. :").ToUpper(); if (productType != string.Empty) { product = productRepo.List().FirstOrDefault(p => p.ProductType.ToUpper() == productType); if (product != null) { order.CostPerSquareFoot = product.CostPerSquareFoot; order.LaborCostPerSquareFoot = product.LaborCostPerSquareFoot; order.ProductType = product.ProductType; break; } if (product == null) { Console.WriteLine("We do not offer that flooring type."); Console.WriteLine("Press any key to try again..."); Console.ReadKey(); } } else { break; } } Console.Clear(); while (true) { decimal area = UserIO.GetAreaFromUserCanBe0($"Please enter the new area information for this order. The current area is {order.Area}. If you do no wish to change this field hit enter without entering any data. :"); if (area == 0) { break; } else { order.Area = area; break; } } order.MaterialCost = order.Area * order.CostPerSquareFoot; order.LaborCost = order.Area * order.LaborCostPerSquareFoot; order.Total = order.MaterialCost + order.LaborCost + order.Tax; order.Tax = (order.MaterialCost + order.LaborCost) * (order.TaxRate / 100); order.OrderDate = response.Date; order.MaterialCost.ToString(); order.LaborCost.ToString(); order.Tax.ToString(); order.Total.ToString(); string line = "{0, 5} {1, 10} {2, 12} {3,8} {4, 15} {5, 15} {6, 12} {7, 9} {8, 9}"; Console.WriteLine(line, "Order ID", "Order Date", "Cust Name", "State", "Prod Type", "Material Cost", "Labor Cost", "Tax", "Total"); Console.WriteLine("_______________________________________________________________________________________"); string line2 = "{0, 5} {1, 12} {2, 9} {3, 10} {4, 14} {5, 12} {6, 16} {7, 11} {8, 11}"; Console.WriteLine(line2, order.OrderNumber, order.OrderDate.ToString("MM/dd/yyyy"), order.CustomerName, order.State, order.ProductType, String.Format("{0:0.00}", order.MaterialCost), String.Format("{0:0.00}", order.LaborCost), String.Format("{0:0.00}", order.Tax), String.Format("{0:0.00}", order.Total)); string input = UserIO.GetYesOrNoFromUser($"Do you want to save these changes for {order.CustomerName}?"); if (input == "Y") { EditOrderResponse editResponse = manager.OrderEdit(order); if (editResponse.Success == true) { Console.WriteLine("The order has been added."); Console.WriteLine("Press any key to continue..."); Console.ReadLine(); } else { Console.WriteLine(editResponse.Message); Console.WriteLine("The request has been cancelled. Press any key to return to the main menu"); Console.ReadKey(); } } else { Console.WriteLine("You have chosen not to save the changes to the order. Press any key to return to the main menu."); Console.ReadKey(); } } else { Console.WriteLine("There are no orders from that date."); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } }
public void Execute() { OrderManager manager = OrderManagerFactory.Create(); DateTime date = UserIO.GetDateFromUser("Enter the date the order was placed (example \"MM-DD-YYYY\"):"); DisplayOrderResponse response = manager.OrderLookup(date); if (response.Success) { ConsoleIO.DisplayOrderDetails(response.Order, response.Date); Order order = UserIO.GetOrderFromUser("Which order would you like to remove? (Use Order ID) :", response.Order); Console.Clear(); order.MaterialCost.ToString(); order.LaborCost.ToString(); order.Tax.ToString(); order.Total.ToString(); string line = "{0, 5} {1, 10} {2, 12} {3,8} {4, 15} {5, 15} {6, 12} {7, 9} {8, 9}"; Console.WriteLine(line, "Order ID", "Order Date", "Cust Name", "State", "Prod Type", "Material Cost", "Labor Cost", "Tax", "Total"); Console.WriteLine("_______________________________________________________________________________________"); string line2 = "{0, 5} {1, 12} {2, 9} {3, 10} {4, 14} {5, 12} {6, 16} {7, 11} {8, 11}"; Console.WriteLine(line2, order.OrderNumber, date.ToString("MM/dd/yyyy"), order.CustomerName, order.State, order.ProductType, String.Format("{0:0.00}", order.MaterialCost), String.Format("{0:0.00}", order.LaborCost), String.Format("{0:0.00}", order.Tax), String.Format("{0:0.00}", order.Total)); string input = null; while (input == null) { input = UserIO.GetYesOrNoFromUser("Do you want to remove this order?"); if (string.IsNullOrEmpty(input)) { Console.WriteLine("You must enter either Y or N"); Console.WriteLine("Press any key to try again"); Console.ReadKey(); input = null; } else { if (input != "Y" && input != "N") { Console.WriteLine("You must enter either Y or N"); Console.WriteLine("Press any key to try again"); Console.ReadKey(); input = null; } else if (input == "Y") { RemoveOrderResponse removeResponse = manager.OrderRemove(date, order.OrderNumber, order); if (removeResponse.Success == true) { Console.WriteLine(removeResponse.Message); Console.ReadKey(); } else { Console.WriteLine(removeResponse.Message); Console.ReadKey(); } } else if (input == "N") { Console.WriteLine("You have chosen to cancel the remove order request. It will not be removed. Press any to return to the main menuc"); Console.ReadKey(); } } } } else { Console.WriteLine("There are no orders from that date."); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } Console.Clear(); }
public void Execute() { Console.Clear(); Console.WriteLine(" Add Order"); ConsoleIO.DisplaySeparatorBar(); Order order = new Order(); int originalOrderNumber = 0; order.OrderDate = UserIO.GetFutureDateFromUser("Enter the Order Date. This date must be in the future. :"); TaxesRepository taxRepo = new TaxesRepository(); ConsoleIO.DisplayTaxRepo(taxRepo.List()); Taxes tax = null; while (tax == null) { string state = UserIO.GetStringFromUserCanBeNull($"Please enter the state Abbreviation for the customer. :").ToUpper(); if (state != string.Empty) { tax = taxRepo.List().FirstOrDefault(t => t.StateAbbreviation.ToUpper() == state); if (tax != null) { order.State = tax.StateAbbreviation.ToUpper(); order.TaxRate = tax.TaxRate; break; } else { Console.WriteLine("We do not do business in that state"); Console.WriteLine("Press any key to try again..."); Console.ReadLine(); } } else { Console.WriteLine("This may not be empty. Press any key to try again"); Console.ReadKey(); } } Console.Clear(); ProductRepository productRepo = new ProductRepository(); ConsoleIO.DisplayProductRepo(productRepo.List()); Product product = null; while (product == null) { string productType = UserIO.GetStringFromUserCanBeNull($"Please enter the product type information for the customer. :").ToUpper(); if (productType != string.Empty) { product = productRepo.List().FirstOrDefault(p => p.ProductType.ToUpper() == productType); if (product != null) { order.CostPerSquareFoot = product.CostPerSquareFoot; order.LaborCostPerSquareFoot = product.LaborCostPerSquareFoot; order.ProductType = product.ProductType.ToUpper(); break; } if (product == null) { Console.WriteLine("We do not offer that flooring type."); Console.WriteLine("Press any key to try again..."); Console.ReadKey(); } } else { Console.WriteLine("This may not be empty. Press any key to try again."); Console.ReadKey(); } } Console.Clear(); order.Area = UserIO.GetAreaFromUser("Enter the order area (\"Must be more than 100 square feet\") :"); while (true) { string customerName = UserIO.GetStringFromUserCanBeNull($"Please enter a name for the customer. This can only contain Letters, Digits, periods, commas, or spaces. :"); if (customerName.Trim() == string.Empty) { Console.WriteLine("The name customer name cannot be blank. Press any key to try again."); Console.ReadKey(); Console.Clear(); continue; } bool result = customerName.All(c => Char.IsLetterOrDigit(c) || c == '.' || c == ',' || c == ' '); if (result == false) { Console.WriteLine("The customer name you entered contained an invalid value. Press any key to try again"); Console.ReadKey(); Console.Clear(); } else { order.CustomerName = customerName; break; } } Console.Clear(); order.MaterialCost = order.Area * order.CostPerSquareFoot; order.LaborCost = order.Area * order.LaborCostPerSquareFoot; order.Tax = (order.MaterialCost + order.LaborCost) * (order.TaxRate / 100); order.Total = order.MaterialCost + order.LaborCost + order.Tax; OrderManager manager = OrderManagerFactory.Create(); order.MaterialCost.ToString(); order.LaborCost.ToString(); order.Tax.ToString(); order.Total.ToString(); string line = "{0, 5} {1, 10} {2, 12} {3,8} {4, 15} {5, 15} {6, 12} {7, 9} {8, 9}"; Console.WriteLine(line, "Order ID", "Order Date", "Cust Name", "State", "Prod Type", "Material Cost", "Labor Cost", "Tax", "Total"); Console.WriteLine("_______________________________________________________________________________________"); string line2 = "{0, 5} {1, 12} {2, 9} {3, 10} {4, 14} {5, 12} {6, 16} {7, 11} {8, 11}"; Console.WriteLine(line2, order.OrderNumber, order.OrderDate.ToString("MM/dd/yyyy"), order.CustomerName, order.State, order.ProductType, String.Format("{0:0.00}", order.MaterialCost), String.Format("{0:0.00}", order.LaborCost), String.Format("{0:0.00}", order.Tax), String.Format("{0:0.00}", order.Total)); string input = UserIO.GetYesOrNoFromUser($"Do you want to add this order new order for {order.CustomerName}?"); if (input == "Y") { AddOrderResponse addResponse = manager.OrderAdd(order.OrderDate, order, originalOrderNumber); if (addResponse.Success == true) { Console.WriteLine("The order has been added."); Console.WriteLine("Press any key to continue..."); Console.ReadLine(); } else { Console.WriteLine(addResponse.Message); Console.WriteLine("The request has been cancelled. Press any key to return to the main menu"); Console.ReadKey(); } } else { Console.WriteLine("Add order request has been cancelled. Press any key to return to the main menu."); Console.ReadKey(); } }