public OrderEditResponse EditOrder(int orderNumber, string date, string customerName, string state, string productType, decimal area) { Validation validate = new Validation(); OrderDateExist dateExist = new OrderDateExist(); dateExist.IsAreaCorrect = validate.Area(area); dateExist.IsNameCorrect = validate.CharactersValidation(customerName); OrderEditResponse response = new OrderEditResponse(); if (!dateExist.IsAreaCorrect) { response.Success = false; response.Message = "Area is not over 100"; return(response); } if (!dateExist.IsNameCorrect) { response.Success = false; response.Message = "Invalid characters for name"; return(response); } response.Order = _orderRepository.SaveOrder(orderNumber, date, customerName, state, productType, area); response.Success = true; return(response); }
//Update existing order public Order SaveOrder(int orderNumber, string date, string customerName, string state, string productType, decimal area) { var givenDate = date.Replace("/", ""); Order order; OrderEditResponse editList = new OrderEditResponse(); var existingOrder = orderList.FirstOrDefault(x => x.OrderNumber == orderNumber); var getOrderNumber = existingOrder.OrderNumber; existingOrder.Date = givenDate; existingOrder.CustomerName = customerName; existingOrder.State = taxesFile.StateAbbreviation(state); existingOrder.StateName = taxesFile.StateName(existingOrder.State); existingOrder.TaxRate = taxesFile.TaxRate(existingOrder.State); existingOrder.ProductType = productsFile.ProductType(productType); existingOrder.Area = area; existingOrder.CostPerSquareFoot = productsFile.CostPerSquareFoot(existingOrder.ProductType); existingOrder.LaborCostPerSquareFoot = productsFile.LaborCostPerSquareFoot(existingOrder.ProductType); existingOrder.MaterialCost = existingOrder.Area * existingOrder.CostPerSquareFoot; existingOrder.LaborCost = existingOrder.Area * existingOrder.LaborCostPerSquareFoot; existingOrder.Tax = (existingOrder.MaterialCost + existingOrder.LaborCost) * (existingOrder.TaxRate / 100); existingOrder.Total = existingOrder.MaterialCost + existingOrder.LaborCost + existingOrder.Tax; if (!Order.TryParse(getOrderNumber, existingOrder.Date, existingOrder.CustomerName, existingOrder.State, existingOrder.StateName, existingOrder.TaxRate, existingOrder.ProductType, existingOrder.Area, existingOrder.CostPerSquareFoot, existingOrder.LaborCostPerSquareFoot, existingOrder.MaterialCost, existingOrder.LaborCost, existingOrder.Tax, existingOrder.Total, out order)) { return(editList.Order = null); } return(existingOrder); }
public void CanEditOrders() { OrderManager manager = OrderManagerFactory.Create(); OrderAddResponse response = new OrderAddResponse(); string orderDate = "12202021"; Order addOrder = new Order { CustomerName = "Bob", State = "OH", ProductType = "Wood", Area = 150.00M }; response = manager.AddOrder(orderDate, addOrder); Assert.AreEqual("Bob", response.OrderList.Orders[2].CustomerName); Assert.AreEqual("OH", response.OrderList.Orders[2].State); Assert.AreEqual("Wood", response.OrderList.Orders[2].ProductType); Assert.AreEqual(150.00M, response.OrderList.Orders[2].Area); OrderEditResponse editedResponse = new OrderEditResponse(); Order editedOrder = new Order { CustomerName = "Bob", State = "PA", ProductType = "Wood", Area = 100.00M }; editedResponse = manager.EditOrder(orderDate, editedOrder, 0); Assert.AreEqual(100.00, editedResponse.OrderList.Orders[0].Area); }
public OrderEditResponse CheckOrderExist(int orderNumber, string date) { Validation validate = new Validation(); OrderDateExist dateExist = new OrderDateExist(); dateExist.IsDateFormatOk = validate.ValidFormat(date); dateExist.DoesOrderDateExist = _orderRepository.FindDate(date); OrderEditResponse response = new OrderEditResponse(); response.Order = _orderRepository.LoadOrder(orderNumber); if (dateExist.IsDateFormatOk == false) { response.Message = "Order date format was invalid."; return(response); } if (dateExist.DoesOrderDateExist && response.Order != null) { response.Success = true; return(response); } else { response.Success = false; response.Message = "Order Number does not exist."; } return(response); }
public OrderEditResponse Edit(OrderInfo orderInfo) { OrderEditResponse response = DIContainer.Kernel.Get <OrderEditResponse>(); response.Success = false; response.OrderInfo = orderInfo; if (orderInfo.OrderDate != _orderRepository.GetOrderDate()) { _orderRepository.FetchOrders(orderInfo.OrderDate); } var fileresponse = _orderRepository.GetOrder(orderInfo); if (!fileresponse.Success) { response.Message = $"{orderInfo.OrderNumber} is not a valid Order."; } else { response.OrderInfo = fileresponse.OrderInfo; response.Success = fileresponse.Success; } return(response); }
public OrderEditResponse Edit(Orders userEdit, string orderDate, int orderNumber) { OrderEditResponse response = new OrderEditResponse(); //response.Orders = _orderRepository.FindOrder(orderDate); if (userEdit == null) { response.Success = false; response.Message = $"{orderDate} or {orderDate} is not a valid date."; return(response); } else { response.Success = true; } IEditOrderRepo editRule = EditOrderRulesFactory.Create(); response = editRule.OrderEdit(userEdit, orderDate, orderNumber); if (response.Success) { _orderRepository.OrdersEdit(userEdit, orderDate, orderNumber); //_orderRepository.SaveOrder(response.Orders); } return(response); }
public OrderEditResponse EditOrder(string OrderDate, Order Order, int OrderNumber) { //Can Only change CustomerName, State, ProductType, Area OrderEditResponse response = new OrderEditResponse(); Order oldOrder = _orderRepository.LoadOrder(OrderDate, OrderNumber); response.OrderList = _orderRepository.List(OrderDate); _Tax = _orderRepository.LoadTaxes(); _Products = _orderRepository.LoadProducts(); //return orders then match it up if (Order.State != oldOrder.State && Order.State != null) { //This is abbriv oldOrder.State = Order.State; Tax tax = _Tax.FirstOrDefault(p => p.StateAbbreviation == Order.State); oldOrder.TaxRate = tax.TaxRate; } if (Order.ProductType != oldOrder.ProductType) { oldOrder.ProductType = Order.ProductType; Products products = _Products.FirstOrDefault(p => p.ProductType == Order.ProductType); oldOrder.LaborCostPerSquareFoot = products.LaborCostPerSquareFoot; oldOrder.CostPerSquareFoot = products.CostPerSquareFoot; //Get Cost Per Square Foot //Get Labor Cost } if (Order.Area != oldOrder.Area) { oldOrder.Area = Order.Area; } if (Order.CustomerName != oldOrder.CustomerName) { oldOrder.CustomerName = Order.CustomerName; } oldOrder = OrderCalculations(oldOrder); response.OrderList.Orders[OrderNumber] = oldOrder; //Show new price if Changed if (response.OrderList.Orders[OrderNumber] == null) { response.Success = false; response.Message = "Order could not be Edited"; } else { // _orderRepository.SaveOrder(response.Order, OrderNumber); _orderRepository.SaveOrder(response.OrderList, response.OrderList.OrderDate); response.Success = true; } return(response); }
public OrderEditResponse OrderEdit(Orders userEdit, string orderDate, int orderNumber) { OrderEditResponse response = new OrderEditResponse(); response.Orders = userEdit; response.orderDate = orderDate; response.orderNumber = orderNumber; response.Success = true; return(response); }
//Update existing order public Order SaveOrder(int orderNumber, string date, string customerName, string state, string productType, decimal area) { var givenDate = date.Replace("/", ""); string orderFileName = $"{fp.filePathLoc}\\Orders_{givenDate}.txt"; string header = "OrderNumber,CustomerName,State,TaxRate,ProductType,Area,CostPerSquareFoot," + "LaborCostPerSquareFoot,MaterialCost,LaborCost,Tax,Total"; Order order; OrderEditResponse editList = new OrderEditResponse(); var existingOrder = orderList.FirstOrDefault(x => x.OrderNumber == orderNumber); var getOrderNumber = existingOrder.OrderNumber; existingOrder.Date = givenDate; existingOrder.CustomerName = customerName; existingOrder.State = taxesFile.StateAbbreviation(state); existingOrder.StateName = taxesFile.StateName(existingOrder.State); existingOrder.TaxRate = taxesFile.TaxRate(existingOrder.State); existingOrder.ProductType = productsFile.ProductType(productType); existingOrder.Area = area; existingOrder.CostPerSquareFoot = productsFile.CostPerSquareFoot(existingOrder.ProductType); existingOrder.LaborCostPerSquareFoot = productsFile.LaborCostPerSquareFoot(existingOrder.ProductType); existingOrder.MaterialCost = existingOrder.Area * existingOrder.CostPerSquareFoot; existingOrder.LaborCost = existingOrder.Area * existingOrder.LaborCostPerSquareFoot; existingOrder.Tax = (existingOrder.MaterialCost + existingOrder.LaborCost) * (existingOrder.TaxRate / 100); existingOrder.Total = existingOrder.MaterialCost + existingOrder.LaborCost + existingOrder.Tax; if (!Order.TryParse(getOrderNumber, existingOrder.Date, existingOrder.CustomerName, existingOrder.State, existingOrder.StateName, existingOrder.TaxRate, existingOrder.ProductType, existingOrder.Area, existingOrder.CostPerSquareFoot, existingOrder.LaborCostPerSquareFoot, existingOrder.MaterialCost, existingOrder.LaborCost, existingOrder.Tax, existingOrder.Total, out order)) { return(editList.Order = null); } List <string> ordersToSave = new List <string>() { header }; ordersToSave.AddRange(orderList.Select(x => x.ToString()).ToList()); File.WriteAllLines(orderFileName, ordersToSave); return(existingOrder); }
[TestCase("10/16/2016", 1, "Lord Edgesworth II", "OH", 456, true)] //Change everything. True. public void EditOrderTest(string orderDateString, int orderNumber, string name, string state, int area, bool expectedResult) { OrderManager editTester = OrderManagerFactory.Create(); DateTime orderDate; DateTime.TryParse(orderDateString, out orderDate); Order editedOrder = new Order(); editedOrder.Name = name; editedOrder.OrderNumber = orderNumber; editedOrder.State = state; editedOrder.Area = area; editedOrder.OrderDate = orderDate; OrderEditResponse response = editTester.EditOrder(editedOrder, orderNumber); Assert.AreEqual(expectedResult, response.Success); }
public OrderEditResponse EditOrder(Order editedOrder, int orderNumber) { OrderEditResponse response = new OrderEditResponse(); Validation(editedOrder, response); if (response.Success == false) { return(response); } List <Order> orders = _orderRepository.List(editedOrder.OrderDate); if (orders == null || orders.Count == 0) { response.Success = false; return(response); } else { foreach (var order in orders) { if (orderNumber != order.OrderNumber) { continue; } else { _orderRepository.Edit(editedOrder, orderNumber); response.Success = true; response.Message = "Order Edited"; return(response); } } response.Success = false; return(response); } }
public void Execute() { Console.Clear(); OrderManager manager = OrderManagerFactory.Create(); Console.WriteLine("Edit an Order"); Console.WriteLine("--------------------"); Console.WriteLine("Enter Order Number: "); string orderNumberInput = Console.ReadLine(); int.TryParse(orderNumberInput, out int orderNumber); string date; while (true) { Console.WriteLine("Enter existing date as (MM/dd/yyyy): "); string dateInput = Console.ReadLine(); if (dateInput == "") { Console.WriteLine("null not allowed"); continue; } else { date = dateInput; } break; } OrderEditResponse response = manager.CheckOrderExist(orderNumber, date); if (response.Success) { Console.WriteLine($"Enter Customer Name({response.Order.CustomerName}): "); string customerName = Console.ReadLine(); if (customerName == "") { customerName = response.Order.CustomerName; } Console.WriteLine($"Enter State({response.Order.State}): "); string state = Console.ReadLine(); if (state == "") { state = response.Order.State; } Console.WriteLine($"Enter Product Type({response.Order.ProductType}): "); string productType = Console.ReadLine(); if (productType == "") { productType = response.Order.ProductType; } Console.WriteLine($"Enter Area({response.Order.Area}): "); decimal area; string areaInput = Console.ReadLine(); if (areaInput == "") { area = response.Order.Area; } else { decimal.TryParse(areaInput, out area); } Console.WriteLine($"Order Number: {orderNumber}"); Console.WriteLine($"Date: {date}"); Console.WriteLine($"Name: {customerName}"); Console.WriteLine($"State: {state}"); Console.WriteLine($"Product: {productType}"); Console.WriteLine($"Area: {area}"); Console.WriteLine("Are you sure you want to save these values (y/n)?"); string inputSave = Console.ReadLine(); if (inputSave == "Y" || inputSave == "y") { OrderEditResponse newResponse = manager.EditOrder(orderNumber, date, customerName, state, productType, area); } else { response.Message = "Save Cancelled"; response.Success = false; } if (response.Success) { Console.WriteLine("Order edited from list!"); Console.WriteLine($"Order Number: {response.Order.OrderNumber}"); Console.WriteLine($"Future date: {response.Order.Date}"); Console.WriteLine($"Customer Name: {response.Order.CustomerName}"); Console.WriteLine($"State: {response.Order.State}"); Console.WriteLine($"Tax Rate: {response.Order.TaxRate}"); Console.WriteLine($"Product Type: {response.Order.ProductType}"); Console.WriteLine($"Area: {response.Order.Area}"); Console.WriteLine($"Cost Per Square: ${response.Order.CostPerSquareFoot.ToString("#.##")}"); Console.WriteLine($"Labor Cost Per Square Foot: ${response.Order.LaborCostPerSquareFoot.ToString("#.##")}"); Console.WriteLine($"Tax: ${response.Order.Tax.ToString("#.##")}"); Console.WriteLine($"Total: ${response.Order.Total.ToString("#.##")}"); } else if (!response.Success) { Console.WriteLine($"{response.Message}"); } } else { Console.WriteLine($"An error has occured: {response.Message}"); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
public void Execute() { Console.Clear(); var orderInfo = DIContainer.Kernel.Get <OrderInfo>(); orderInfo.OrderDate = Input.GetOrderDate(); orderInfo.OrderNumber = Input.GetOrderNumber(); var states = manager.GetStates(); var products = manager.GetProducts(); OrderEditResponse response = manager.Edit(orderInfo); if (response.Success) { string customerName = String.Empty; TaxInfo state; ProductInfo product; decimal area; bool dataChanged = false; Output.SendToConsole("Order before changes\n"); Output.SendToConsole(response.OrderInfo); customerName = Input.GetCustomerName(response.OrderInfo.Order.CustomerName); if (customerName != response.OrderInfo.Order.CustomerName) { response.OrderInfo.Order.CustomerName = customerName; dataChanged = true; } var stateExists = states.States.Exists(s => s.StateAbbreviation == response.OrderInfo.Order.State); if (stateExists) { state = Input.GetState(response.OrderInfo.Order.State, states.States); if (state != null) { if (state.StateAbbreviation != response.OrderInfo.Order.State) { dataChanged = true; response.OrderInfo.Order.State = state.StateAbbreviation; response.OrderInfo.Order.TaxRate = state.TaxRate; response.OrderInfo.Recalculate = true; } } } else { if (response.OrderInfo.Order.State.Length == 0) { state = Input.GetState(states.States); if (state != null) { dataChanged = true; response.OrderInfo.Order.State = state.StateAbbreviation; response.OrderInfo.Order.TaxRate = state.TaxRate; response.OrderInfo.Recalculate = true; } } } var productExists = products.Products.Exists(p => p.ProductType == response.OrderInfo.Order.ProductType); if (productExists) { product = Input.GetProductType(response.OrderInfo.Order.ProductType, products.Products); if (product != null) { if (product.ProductType != response.OrderInfo.Order.ProductType) { dataChanged = true; response.OrderInfo.Recalculate = true; response.OrderInfo.Order.ProductType = product.ProductType; response.OrderInfo.Order.LaborCostPerSquareFoot = product.LaborCostPerSquareFoot; response.OrderInfo.Order.CostPerSquareFoot = product.CostPerSquareFoot; } } } else { if (response.OrderInfo.Order.ProductType == null) { product = Input.GetProductType(products.Products); if (product != null) { dataChanged = true; response.OrderInfo.Recalculate = true; response.OrderInfo.Order.ProductType = product.ProductType; response.OrderInfo.Order.LaborCostPerSquareFoot = product.LaborCostPerSquareFoot; response.OrderInfo.Order.CostPerSquareFoot = product.CostPerSquareFoot; } } } area = Input.GetArea(response.OrderInfo.Order.Area); if (area != response.OrderInfo.Order.Area) { dataChanged = true; response.OrderInfo.Recalculate = true; } if (dataChanged) { ShowChangesandGetOkay(response.OrderInfo); } else { Output.SendToConsole("No changes made."); } } else { Output.SendToConsole("Error occurred getting order"); } Output.SendToConsole("\nPress any key to continue..."); Console.ReadKey(); }
public void Execute() { string orderDate; int orderNumber; bool isOrderNumberValid; OrderManager manager = OrderManagerFactory.Create(); Console.Clear(); Console.WriteLine("Edit an Order"); Console.WriteLine("-------------------------------"); orderDate = ConsoleIO.validateDateOrder(); //Validate OrderNumber //call orderList from date //get count from list //keep count while (true) { orderNumber = Convert.ToInt32(ConsoleIO.GetRequiredNumberString("Enter Order Number: ")); isOrderNumberValid = manager.OrderNumberCount(orderDate, orderNumber); if (isOrderNumberValid == false) { Console.WriteLine("Not a Valid Order Number"); Console.ReadKey(); } else { break; } } //Look Up Response //Then Edit the Repsonse OrderLookUpResponse lookUpOrder = manager.LookUpOrder(orderDate); Order editedOrder = lookUpOrder.OrderList.Orders[orderNumber]; Console.WriteLine($"Enter customer name [{editedOrder.CustomerName}]: "); string name = Console.ReadLine(); if (!string.IsNullOrEmpty(name)) { editedOrder.CustomerName = name; } Console.WriteLine($"Enter State Name [{editedOrder.State}]: "); string state = Console.ReadLine(); if (!string.IsNullOrEmpty(state)) { //Turn from state name to abbrivation editedOrder.State = state; } Console.WriteLine($"Enter Product Type [{editedOrder.ProductType}]: "); string productType = Console.ReadLine(); if (!string.IsNullOrEmpty(productType)) { editedOrder.ProductType = productType; } Console.WriteLine($"Enter Area [{ editedOrder.Area}]: "); string area = Console.ReadLine(); if (!string.IsNullOrEmpty(area)) { editedOrder.Area = Convert.ToDecimal(area); } //Shows what field was editted OrderEditResponse response = manager.EditOrder(orderDate, editedOrder, orderNumber); if (response.Success) { //List<Order> orders = TestOrderList.LoadOrders(); ConsoleIO.DisplaySingleOrder(response.OrderList.Orders[orderNumber], orderDate); } else { Console.WriteLine("An Error Occured"); Console.WriteLine(response.Message); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
public void Execute() { Console.Clear(); OrderManager orderManager = OrderManagerFactory.Create(); Console.Clear(); Console.WriteLine("Edit an Order"); Console.WriteLine("-------------------------"); bool goodDate = false; string orderDate; do { //must be in the future Console.Write("Enter the date you are interested in (use MMDDYYYY format):\n"); orderDate = Console.ReadLine(); if (orderDate != null && orderDate.Count() == 8) { goodDate = true; continue; } else { Console.WriteLine("Please enter a date in correct format."); goodDate = false; } } while (goodDate == false); bool goodNumber = false; int orderNumber; do { //must be in the future Console.Write("Enter Order Number you wish to edit:\n"); orderNumber = int.Parse(Console.ReadLine()); if (orderNumber <= 0 || orderNumber > 0) { goodNumber = true; continue; } else { Console.WriteLine("Please enter a good order number."); goodNumber = false; } } while (goodNumber == false); Orders passOrderEdit = new Orders(); List <Orders> lastOrders = new List <Orders>(); lastOrders = orderManager._orderRepository.FindOrder(orderDate); if (lastOrders == null) { Console.WriteLine("There are no orders for order number provided. "); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); Menu.Start(); } else { foreach (var order in lastOrders) { if (order.OrderNumber == orderNumber) { passOrderEdit.OrderNumber = order.OrderNumber; passOrderEdit.CustomerName = order.CustomerName; passOrderEdit.State = order.State; passOrderEdit.TaxRate = order.TaxRate; passOrderEdit.ProductType = order.ProductType; passOrderEdit.Area = order.Area; passOrderEdit.CostPerSquareFoot = order.CostPerSquareFoot; passOrderEdit.LaborCostPerSquareFoot = order.LaborCostPerSquareFoot; passOrderEdit.MaterialCost = order.MaterialCost; passOrderEdit.LaborCost = order.LaborCost; passOrderEdit.Tax = order.Tax; passOrderEdit.Total = order.Total; break; } else { continue; } } } Orders userEdit = new Orders(); Console.Write($"Edit CustomerName ({passOrderEdit.CustomerName}):\n"); string editCustomerName = Console.ReadLine(); if (editCustomerName == null) { userEdit.CustomerName = passOrderEdit.CustomerName; } else { userEdit.CustomerName = editCustomerName; } string editState; //decimal editTaxRate; Tax taxChoice = null; bool goodTax = false; do { Console.Write($"Edit State ({passOrderEdit.State}):\n"); editState = Console.ReadLine(); var taxdownload = orderManager._orderRepository.LookUpTax(editState); if (editState == taxdownload.StateName) { taxChoice = taxdownload; userEdit.TaxRate = taxdownload.TaxRate; userEdit.State = taxdownload.StateName; Console.Write($"{taxdownload.StateName} TaxRate is: {taxdownload.TaxRate}\n"); Console.Write($"\n"); goodTax = true; } else if (editState == null) { userEdit.TaxRate = passOrderEdit.TaxRate; userEdit.State = passOrderEdit.State; goodTax = true; } else { Console.Write("Sorry, we cannot sell to this state at this time."); //editTaxRate = 0; goodTax = false; } } while (goodTax == false); string editProductType; Console.Write($"Edit Product Type ({passOrderEdit.ProductType}):\n"); var productDown = orderManager._orderRepository.LookUpProducts(); foreach (var product in productDown) { Console.WriteLine("{0}, {1}, {2}", product.ProductType, product.LaborCostPerSquareFoot, product.CostPerSquareFoot); Console.Write(""); } Console.Write($"\n"); editProductType = Console.ReadLine(); bool goodProduct = false; Products editConfirmedChoice = null; do { //Products confirmedChoice; Console.WriteLine(""); if (editProductType == null) { userEdit.ProductType = passOrderEdit.ProductType; } else { var productChoice = orderManager._orderRepository.ChooseProduct(editProductType); if (productChoice != null) { editConfirmedChoice = productChoice; userEdit.ProductType = productChoice.ProductType; userEdit.CostPerSquareFoot = productChoice.CostPerSquareFoot; userEdit.LaborCostPerSquareFoot = productChoice.LaborCostPerSquareFoot; goodProduct = true; } else { Console.Write("\n You have made an incorrect choice, please choose again."); goodProduct = false; }; } } while (goodProduct == false); bool goodArea = false; decimal editArea; do { Console.Write($"Edit Area ({passOrderEdit.Area}):\n"); editArea = Convert.ToDecimal(Console.ReadLine()); if (editArea >= 100M) { if (editArea.ToString().Count() == 0) { userEdit.Area = passOrderEdit.Area; } else { userEdit.Area = editArea; } goodArea = true; continue; } else { Console.WriteLine("\nArea entered must be positive and greater than 100 sq feet."); goodArea = false; } } while (goodArea == false); decimal costPerSquareFoot; decimal laborCostPerSquareFoot; decimal materialCost; decimal laborCost; decimal tax; decimal total; costPerSquareFoot = editConfirmedChoice.CostPerSquareFoot; laborCostPerSquareFoot = editConfirmedChoice.LaborCostPerSquareFoot; materialCost = userEdit.Area * editConfirmedChoice.CostPerSquareFoot; laborCost = userEdit.Area * editConfirmedChoice.LaborCostPerSquareFoot; tax = ((userEdit.Area * editConfirmedChoice.CostPerSquareFoot) + (userEdit.Area * editConfirmedChoice.LaborCostPerSquareFoot)) * (taxChoice.TaxRate / 100); total = (userEdit.Area * editConfirmedChoice.CostPerSquareFoot) + (userEdit.Area * editConfirmedChoice.LaborCostPerSquareFoot) + (((userEdit.Area * editConfirmedChoice.CostPerSquareFoot) + (userEdit.Area * editConfirmedChoice.LaborCostPerSquareFoot)) * (taxChoice.TaxRate / 100)); userEdit.OrderNumber = orderNumber; userEdit.LaborCost = laborCost; userEdit.MaterialCost = materialCost; userEdit.Tax = tax; userEdit.Total = total; Console.Write($"\nOrderDate is {orderDate}"); Console.Write($"\nOrderNumber is {orderNumber}"); Console.Write($"\nCustomerName is {userEdit.CustomerName}"); Console.Write($"\nStateName is {taxChoice.StateAbbreviation}"); Console.Write($"\nTaxRate is {taxChoice.TaxRate}"); Console.Write($"\nProductType is {userEdit.ProductType}"); Console.Write($"\nCostPerSquareFoot is {costPerSquareFoot}"); Console.Write($"\nLaborCostPerSquareFoot is {laborCostPerSquareFoot}"); Console.Write($"\nMaterialCost: {materialCost}"); Console.Write($"\nLaborCost: {laborCost}"); Console.Write($"\nTax: {tax}"); Console.Write($"\nTotal: {total}"); Console.Write("\n Please review changes above. \n If info seems right, please type Edit to continue or anything else to go back to main menu. \n"); string resp = Console.ReadLine(); if (resp == "Edit") { OrderEditResponse response = orderManager.Edit(userEdit, orderDate, orderNumber); if (response.Success) { ConsoleIO.DisplayOrderDetails(response.Orders, orderDate); } else { Console.WriteLine("An error occurred: "); Console.WriteLine(response.Message); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } else { Menu.Start(); } }
public void Execute() { bool edited; int orderNumber; ConsoleIO.Header(); Console.WriteLine("Edit an Order"); Console.WriteLine(); do { DateTime editDate = ConsoleIO.GetOrderDateFromUser("Please enter a date for the order you wish you edit (MM/DD/YYYY): "); ConsoleIO.Header(); Console.WriteLine("Edit an Order"); Console.WriteLine(); List <Order> orders = ConsoleIO.PrintOrderList(editDate); Console.WriteLine(ConsoleIO.Separator); Console.WriteLine(); if (orders == null) { Console.WriteLine("Press any key to continue."); Console.ReadKey(); return; } Console.WriteLine("Please enter the order number you wish to edit: "); int.TryParse(Console.ReadLine(), out orderNumber); if (orderNumber <= 0) { Console.WriteLine("Order Number is not valid."); Console.WriteLine("Press any key to continue"); Console.ReadKey(); return; } for (int i = 0; i < orders.Count; i++) { if (orderNumber == orders[i].OrderNumber) { break; } else if ((i == orders.Count - 1) && (orders[i].OrderNumber != orderNumber)) { Console.WriteLine("Order Number {0} does not exist on {1}", orderNumber, editDate); Console.WriteLine("Press any key to continue"); Console.ReadKey(); return; } } Order oldOrder = orders[orderNumber - 1]; oldOrder.Name = ConsoleIO.GetOrderNameFromUser(String.Format("Please enter name for the order. Current name : ({0}) ", oldOrder.Name)); oldOrder.State = ConsoleIO.GetOrderStateFromUser(String.Format("Please enter your state initials. Current state: ({0}) ", oldOrder.State)); oldOrder.TaxRate = TaxRepository.GetTaxRate(oldOrder.State); oldOrder.OrderDate = editDate; oldOrder.Type = ConsoleIO.GetProductFromUser(oldOrder.Type); oldOrder.Area = ConsoleIO.GetAreaFromUser(String.Format("Please enter new area amount. Current Area: ({0}) ", oldOrder.Area)); oldOrder.CostLabor = Math.Round(Calculations.GetLaborCost(oldOrder.Type, oldOrder.Area), 2, MidpointRounding.AwayFromZero); oldOrder.CostMaterial = Math.Round(Calculations.GetProductCost(oldOrder.Type, oldOrder.Area), 2, MidpointRounding.AwayFromZero); oldOrder.Tax = Math.Round(ConsoleIO.JustTax(oldOrder.TaxRate, oldOrder.Type, oldOrder.Area, oldOrder.State), 2, MidpointRounding.AwayFromZero); oldOrder.TotalCost = Math.Round(ConsoleIO.GetTotal(oldOrder.TaxRate, oldOrder.Type, oldOrder.Area, oldOrder.State), 2, MidpointRounding.AwayFromZero); string confirmFormat = "{0, -16} {1} \n{2, -16} {3} \n{4, -16} {5:d} \n{6, -16} {7} \n{8, -16} {9} \n \n{10, -16} {11} \n{12, -16} {13} \n{14, -16} {15} \n{16, -16} {17}"; while (true) { string editOrder = ConsoleIO.GetYesNoAnswerFromUser($"Is this information correct? ({oldOrder.Name}, {oldOrder.State}, {oldOrder.Type}, {oldOrder.Area})"); if ((editOrder.ToUpper() == "Y") || (editOrder.ToUpper() == "YES")) { ConsoleIO.Header(); OrderManager orderManager = OrderManagerFactory.Create(); OrderEditResponse response = orderManager.EditOrder(oldOrder, orderNumber); Console.WriteLine(confirmFormat, "Customer Name:", oldOrder.Name, "Customer State:", oldOrder.State, "Order Date:", oldOrder.OrderDate, "Flooring Type:", oldOrder.Type, "Area:", oldOrder.Area + "(sqft)", "Product Cost:", oldOrder.CostMaterial, "Labor Cost:", oldOrder.CostLabor, "Tax:", oldOrder.Tax, "Total:", oldOrder.TotalCost); Console.WriteLine(ConsoleIO.Separator); Console.WriteLine(); Console.WriteLine("Press any key to continue."); Console.ReadKey(); edited = true; break; } else if ((editOrder.ToUpper() == "N") || (editOrder.ToUpper() == "NO")) { ConsoleIO.Header(); Console.WriteLine("Edit cancelled."); Console.WriteLine("Press any key to continue."); Console.ReadKey(); edited = false; return; } else { edited = false; ConsoleIO.Header(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Please enter Y/N only."); Console.ResetColor(); Console.WriteLine(); } } }while (!edited); }