public LoadOrderResponse LoadOrder(string date) { LoadOrderResponse response = new LoadOrderResponse(); DateTime dateParsed; if (!DateTime.TryParse(date, out dateParsed)) { response.Message = $"Not a valid date. Must be in mm/dd/yyyy format. You typed {date}"; response.Success = false; return(response); } List <Order> allOrders = _orderRepository.LoadOrder(date); if (allOrders == null) { response.Success = false; response.Message = "No orders for that date"; return(response); } response.AllOrders = allOrders; response.Success = true; response.Message = "Displayed Orders"; return(response); }
public LoadOrderResponse LoadOrder(string orderDate, int orderNumber) { LoadOrderListResponse displayResponse = LoadOrderList(orderDate); LoadOrderResponse loadResponse = new LoadOrderResponse(); if (displayResponse.Success) { foreach (Order order in displayResponse.Orders) { if (order.OrderNumber == orderNumber) { loadResponse.Order = order; loadResponse.Success = true; } } if (loadResponse.Order == null) { loadResponse.Success = false; loadResponse.Message = "An order with that order number was not found."; } } else { loadResponse.Success = false; loadResponse.Message = displayResponse.Message; } return(loadResponse); }
public void CanAddOrderToRepo(string customerName, string state, string type, int area, string orderDate, bool expectedResult) { OrderManager manager = OrderManagerFactory.Create(); Order newOrder = new Order() { CustomerName = customerName, State = state, FloorType = type, Area = area }; LoadOrderResponse addResponse = manager.LoadNewOrder(newOrder, orderDate); Assert.AreEqual(expectedResult, addResponse.Success); if (addResponse.Success) { manager.AddNewOrder(newOrder, orderDate); LoadOrderListResponse response = manager.LoadOrderList("10/10/20"); var orders = response.Orders; Order check = orders[1]; Assert.AreEqual("Test Man", check.CustomerName); Assert.AreEqual("Tile", check.FloorType); Assert.AreEqual(105, check.Area); } }
public void CanEditExistingOrder(int orderNumber, string customerName, string state, string type, int area) { OrderManager manager = OrderManagerFactory.Create(); LoadOrderResponse orderResponse = manager.LoadOrder("10/10/20", orderNumber); var editOrder = orderResponse.Order; Assert.AreEqual("Dave", editOrder.CustomerName); Assert.AreEqual("MI", editOrder.State); Assert.AreEqual("Wood", editOrder.FloorType); Assert.AreEqual(100, editOrder.Area); editOrder.CustomerName = customerName; editOrder.State = state; editOrder.FloorType = type; editOrder.Area = area; manager.CalculateOrderCosts(editOrder); manager.EditOrder(editOrder, editOrder.OrderNumber - 1, "10/10/20"); var orders = manager.LoadOrderList("10/10/20").Orders; Assert.AreEqual(customerName, orders[0].CustomerName); Assert.AreEqual(state, orders[0].State); Assert.AreEqual(type, orders[0].FloorType); Assert.AreEqual(area, orders[0].Area); }
public void Setup() { string mode = ConfigurationManager.AppSettings["Mode"].ToString(); if (mode == "Prod") { if (File.Exists(_filePath)) { File.Delete(_filePath); } File.Copy(_original, _filePath); } else { OrderManager manager = OrderManagerFactory.Create(); LoadOrderResponse orderResponse = manager.LoadOrder("10/10/20", 1); Order testOrder = orderResponse.Order; testOrder.OrderNumber = 1; testOrder.CustomerName = "Dave"; testOrder.State = "MI"; testOrder.TaxRate = 5.75M; testOrder.FloorType = "Wood"; testOrder.Area = 100M; testOrder.CostPerSquareFoot = 5.15M; testOrder.LaborCostPerSquareFoot = 4.75M; testOrder.MaterialCost = 515.00M; testOrder.LaborCost = 475.00M; testOrder.Tax = 56.93M; testOrder.Total = 1046.925M; } }
internal void Execute() { OrderManager manager = OrderManagerFactory.Create(); Console.Clear(); Console.WriteLine("REMOVE AN ORDER"); Console.WriteLine("*****************"); Console.WriteLine(); DateTime orderDate = ConsoleIO.GetDate(); int orderNumber = ConsoleIO.GetOrderNumber(); LoadOrderResponse response = manager.LoadRequestedOrder(orderDate, orderNumber); if (response.Success) { ConsoleIO.DisplaySingleOrderDetail(response.Order); Console.WriteLine(); Console.WriteLine("Are you sure you want to delete the order above? Y/N"); string userInput = Console.ReadLine().ToUpper(); if (userInput == "Y") { manager.RemoveOrder(response.Order); Console.WriteLine("This order has been removed."); } } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
internal void Execute() { OrderManager manager = OrderManagerFactory.Create(); SaveCurrentOrderRequest request = new SaveCurrentOrderRequest(); request.Order = new Order(); Console.Clear(); DateTime orderDate = ConsoleIO.GetDate(); int orderNumber = ConsoleIO.GetOrderNumber(); LoadOrderResponse response = manager.LoadRequestedOrder(orderDate, orderNumber); if (response.Success) { ConsoleIO.DisplaySingleOrderDetail(response.Order); Console.WriteLine("**************************************************"); Console.WriteLine(); Console.WriteLine(); ConsoleIO.MenuForEditOrder(response.Order); } else { response.Success = false; response.Message = "An error occured: "; } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
public void Execute() { OrderManager manager = OrderManagerFactory.Create(); ConsoleIO.NewOrderHeader(); string orderDate = ConsoleIO.GetOrderDateFromUser("Please enter date for work to be done: ", true); ConsoleIO.NewOrderHeader(); string customerName = ConsoleIO.GetStringFromUser("Please enter customer name: "); ConsoleIO.NewOrderHeader(); ConsoleIO.PrintStateList(); string state = ConsoleIO.GetStateAbbreviationFromUser("Please enter the two letter abbreviation for the state where the work is being done: "); ConsoleIO.NewOrderHeader(); var products = manager.GetProductsList().ProductList; int productIndex = ConsoleIO.GetProductChoiceFromUser(); ConsoleIO.NewOrderHeader(); decimal area = ConsoleIO.GetAreaFromUser("Please enter the area of floor in square feet: "); ConsoleIO.NewOrderHeader(); Order newOrder = new Order() { CustomerName = customerName, State = state, FloorType = products[productIndex].FloorType, Area = area }; LoadOrderResponse response = manager.LoadNewOrder(newOrder, orderDate); if (response.Success) { ConsoleIO.PrintOrders(response.Order, orderDate); Console.WriteLine(); Console.WriteLine("Would you like to place this order? (Y/N)"); string confirm = Console.ReadLine().ToUpper(); if (confirm == "Y") { manager.AddNewOrder(response.Order, orderDate); Console.WriteLine("Thank you, your order has been placed."); } } else { Console.WriteLine("An error occured: "); Console.WriteLine(response.Message); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
public void Execute() { OrderManager manager = OrderManagerFactory.Create(); Console.Clear(); Console.WriteLine("Display Orders"); Console.WriteLine("*********************************************"); string orderDate = ConsoleIO.GetOrderDateFromUser("Enter the order date: ", true); LoadOrderListResponse orderListResponse = manager.LoadOrderList(orderDate); if (orderListResponse.Success) { int orderNumber = ConsoleIO.GetOrderNumberFromUser("Please enter the order number: "); int orderIndex = orderNumber - 1; LoadOrderResponse orderResponse = manager.LoadOrder(orderDate, orderNumber); if (orderResponse.Success) { Console.Clear(); ConsoleIO.PrintOrders(orderResponse.Order, orderDate); Console.WriteLine(); Console.WriteLine("Are you sure you want to cancel this order? (Y/N)"); string confirm = Console.ReadLine().ToUpper(); if (confirm == "Y") { Console.WriteLine("This order has been cancelled."); manager.RemoveOrder(orderIndex, orderDate); } } else { Console.WriteLine("An error occured: "); Console.WriteLine(orderResponse.Message); } } else { Console.WriteLine("An error occured: "); Console.WriteLine(orderListResponse.Message); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
public LoadOrderResponse LoadRequestedOrder(DateTime orderDate, int orderNumber) { LoadOrderResponse response = new LoadOrderResponse(); response.Order = _orderRepository.LoadOrder(orderDate, orderNumber); if (response.Order == null) { response.Success = false; response.Message = ($"{orderDate} does not exist!"); } else { response.Success = true; } return(response); }
public LoadOrderResponse LoadNewOrder(Order order, string date) { LoadOrderResponse response = new LoadOrderResponse(); GetTaxRateResponse taxInfo = GetTaxInfo(order.State); response.Order = order; if (response.Order.Area < 100) { response.Success = false; response.Message = "The minimum order area is 100 square feet!"; return(response); } if (!taxInfo.Success) { response.Success = false; response.Message = taxInfo.Message; return(response); } if (DateTime.TryParse(date, out DateTime orderDate)) { if (orderDate.CompareTo(DateTime.Now) <= 0) { response.Success = false; response.Message = "The Date for the work to be done must be in the future."; return(response); } } if (response.Order.CustomerName == "") { response.Success = false; response.Message = "Customer name cannot be blank."; return(response); } else { response.Success = true; response.Order.OrderNumber = GetOrderNumber(date); CalculateOrderCosts(response.Order); } return(response); }
public static void Execute() { Console.Clear(); OrderManager orderManager = OrderManagerFactory.Create(); Console.WriteLine("Enter a date: "); string date = Console.ReadLine(); LoadOrderResponse response = orderManager.LoadOrder(date); if (response.Success == false) { Console.WriteLine(response.Message); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); return; } else { foreach (var order in response.AllOrders) { Console.WriteLine(); Console.WriteLine($"{order.OrderNumber} | {order.OrderDate}"); Console.WriteLine(order.CustomerName); Console.WriteLine(order.State); Console.WriteLine(order.ProductType); Console.WriteLine(order.MaterialCost); Console.WriteLine(order.LaborCost); Console.WriteLine(order.Tax); Console.WriteLine(order.Total); Console.WriteLine(); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); return; } }
public void Execute() { OrderManager manager = OrderManagerFactory.Create(); bool recalculate = false; ConsoleIO.EditOrderHeader(); string orderDate = ConsoleIO.GetOrderDateFromUser("Please enter the order date: ", false); LoadOrderListResponse orderListResponse = manager.LoadOrderList(orderDate); if (orderListResponse.Success) { int orderNumber = ConsoleIO.GetOrderNumberFromUser("Please enter the order number: "); LoadOrderResponse orderResponse = manager.LoadOrder(orderDate, orderNumber); if (orderResponse.Success) { Order editOrder = orderResponse.Order; Order originalOrder = new Order() { OrderNumber = editOrder.OrderNumber, CustomerName = editOrder.CustomerName, State = editOrder.State, FloorType = editOrder.FloorType, Area = editOrder.Area, MaterialCost = editOrder.MaterialCost, LaborCost = editOrder.LaborCost, Tax = editOrder.Tax, Total = editOrder.Total }; ConsoleIO.EditOrderHeader(); ConsoleIO.PrintOrders(editOrder, orderDate); Console.WriteLine("Would you like to edit the customer name? Press 'Y' to edit. Press any other key to skip"); string userInput = Console.ReadLine().ToUpper(); if (userInput == "Y") { editOrder.CustomerName = ConsoleIO.GetStringFromUser("Please enter the new customer name: "); } ConsoleIO.EditOrderHeader(); ConsoleIO.PrintOrders(editOrder, orderDate); Console.WriteLine("Would you like to change the state where the work is being done? Press 'Y' to edit. Press any other key to skip."); userInput = Console.ReadLine().ToUpper(); if (userInput == "Y") { ConsoleIO.PrintStateList(); editOrder.State = ConsoleIO.GetStateAbbreviationFromUser("Please enter the two letter abbreviation for the state where the work is being done: "); recalculate = true; } ConsoleIO.EditOrderHeader(); ConsoleIO.PrintOrders(editOrder, orderDate); Console.WriteLine("Would you like to change the flooring material? Press 'Y' to edit. Press any other key to skip."); userInput = Console.ReadLine().ToUpper(); if (userInput == "Y") { var products = manager.GetProductsList().ProductList; int productIndex = ConsoleIO.GetProductChoiceFromUser(); editOrder.FloorType = products[productIndex].FloorType; recalculate = true; } ConsoleIO.EditOrderHeader(); ConsoleIO.PrintOrders(editOrder, orderDate); Console.WriteLine("Would you like to change the flooring area? Press 'Y' to edit. Press any other key to skip."); userInput = Console.ReadLine().ToUpper(); if (userInput == "Y") { editOrder.Area = ConsoleIO.GetAreaFromUser("Please enter the new square footage: "); recalculate = true; } if (recalculate) { manager.CalculateOrderCosts(editOrder); } ConsoleIO.EditOrderHeader(); Console.WriteLine("Original Order: "); ConsoleIO.PrintOrders(originalOrder, orderDate); Console.WriteLine(); Console.WriteLine("Edits Made: "); ConsoleIO.PrintOrders(editOrder, orderDate); Console.WriteLine(); Console.WriteLine("Confirm changes to order? (Y/N)"); string confirm = Console.ReadLine().ToUpper(); if (confirm == "Y") { Console.WriteLine("Your changes have been made."); manager.EditOrder(editOrder, editOrder.OrderNumber - 1, orderDate); } } else { Console.WriteLine("An error occured: "); Console.WriteLine(orderResponse.Message); } } else { Console.WriteLine("An error occured: "); Console.WriteLine(orderListResponse.Message); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }