public Order MakeCalculations(Order Order, DateTime Date, string CustomerName, string State, string ProductType, decimal Area) { List <Taxes> Taxes = new List <Taxes>(); Taxes = ReadFromTaxesFile.ReadTaxes(FilePaths.TaxesFilePath); List <Product> Products = new List <Product>(); Products = ReadFromProductsFile.ReadProducts(FilePaths.ProductsFilePath); List <Order> Orders = new List <Order>(); Orders = ReadOrdersFromFile.ReadOrders(FilePath.GetFilePath(Date)); if (Orders.Count == 0) { Order.OrderNumber = 1; } else { var maxOrderNumber = Orders.Max(order => order.OrderNumber); Order.OrderNumber = maxOrderNumber + 1; } var stateTaxRate = Taxes.Where(state => state.StateAbbreviation.ToUpper() == State.ToUpper()).Select(state => state.TaxRate); //some kind of problem here when editing foreach (var tax in stateTaxRate) { Order.TaxRate = Math.Round(tax, 2); break; } var costPerSqFoot = Products.Where(product => product.ProductType.ToLower() == ProductType.ToLower()).Select(product => product.CostPerSquareFoot); foreach (var cost in costPerSqFoot) { Order.CostPerSquareFoot = Math.Round(cost, 2); break; } var laborCostPerSqFoot = Products.Where(product => product.ProductType.ToLower() == ProductType.ToLower()).Select(product => product.LaborCostPerSquareFoot); foreach (var cost in laborCostPerSqFoot) { Order.LaborCostPerSquareFoot = Math.Round(cost, 2); break; } Order.MaterialCost = Math.Round((Area * Order.CostPerSquareFoot), 2); Order.LaborCost = Math.Round((Area * Order.LaborCostPerSquareFoot), 2); Order.Tax = Math.Round(((Order.MaterialCost + Order.LaborCost) * (Order.TaxRate / 100)), 2); Order.Total = Math.Round((Order.MaterialCost + Order.LaborCost + Order.Tax), 2); return(Order); }
List <Order> IOrderRepository.LoadOrders(DateTime Date) { _filePath = FilePath.GetFilePath(Date); if (!File.Exists(_filePath)) { return(null); } else { _orders = ReadOrdersFromFile.ReadOrders(_filePath); return(_orders); } }
public void Execute() { OrderManager manager = OrderManagerFactory.Create(); Order order = new Order(); bool orderExists; EditOrderInFile editInFile = new EditOrderInFile(); DateTime orderDate = new DateTime().Date; Calculations caluclate = new Calculations(); PrintReceipt print = new PrintReceipt(); OrderLookupResponse lookupResponse = new OrderLookupResponse(); EditOrderResponse editResponse = new EditOrderResponse(); EditOrderRule editRules = new EditOrderRule(); List <Order> Orders = new List <Order>(); bool exception = false; while (true) { while (true) { Console.Clear(); Console.WriteLine("Edit an order"); Console.WriteLine(TextHelper.ConsoleBar); Console.WriteLine("Please enter the following information...."); Console.WriteLine(); Console.WriteLine("Date of order: "); if (DateTime.TryParse(Console.ReadLine(), out orderDate)) { order.Date = orderDate; break; } else { Console.WriteLine("You did not enter a valid date format. Press any key to continue..."); Console.ReadKey(); Console.Clear(); } } try { lookupResponse = manager.LookupOrder(order.Date); if (lookupResponse != null) { Orders = lookupResponse.Orders; } } catch (Exception ex) { Console.WriteLine("You cannot proceed. Please contact IT."); Console.WriteLine(ex.Message); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); exception = true; break; } if (lookupResponse.success) { break; } else { Console.WriteLine("An error occurred."); Console.WriteLine(lookupResponse.message); continue; } } if (exception == false) { while (true) { Console.Clear(); ConsoleIO.DisplayOrderDetails(lookupResponse.Orders); int orderNumber; Console.WriteLine("Order number: "); if (int.TryParse(Console.ReadLine(), out orderNumber)) { order.OrderNumber = orderNumber; } else { Console.WriteLine("You did not enter a number. Press any key to continue..."); Console.ReadKey(); } string filePath = FilePath.GetFilePath(order.Date); Orders = ReadOrdersFromFile.ReadOrders(filePath); orderExists = editInFile.CheckOrderNumberExists(Orders, order.OrderNumber); if (!orderExists) { Console.WriteLine("That order number does not exist for the date you entered. Press any key to continue..."); Console.ReadKey(); continue; } else { Order singleOrder = Orders.Where(ord => ord.OrderNumber == order.OrderNumber).Single(); order = singleOrder; } order = editInFile.GetNewOrderInfoFromUser(order); order = caluclate.EditCalculations(order, order.Date, order.CustomerName, order.State, order.ProductType, order.Area); editResponse = editRules.EditRules(order.Date, order.CustomerName, order.State, order.ProductType, order.Area, editResponse); if (!editResponse.success) { Console.WriteLine("An error occurred: "); Console.WriteLine(editResponse.message); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } else { break; } } while (true) { print.Print(order); Console.WriteLine("Is the updated order correct (Y/N)?"); string userInput = Console.ReadLine().ToUpper(); switch (userInput) { case "Y": EditOrderFile editOrder = new EditOrderFile(); editOrder.EditOrderToFile(Orders, order.Date); Console.WriteLine("Edit has been saved! Press any key to continue..."); Console.ReadKey(); break; case "N": Console.WriteLine("Edit has been canceled. Press any key to continue..."); Console.ReadKey(); break; default: Console.WriteLine("That was not a valid entry! Press any key to continue..."); Console.ReadKey(); continue; } break; } } }
public void Execute() { OrderManager manager = OrderManagerFactory.Create(); DateTime orderDate = new DateTime().Date; Order order = new Order(); List <Order> Orders = new List <Order>(); OrderLookupResponse lookupResponse = new OrderLookupResponse(); bool orderExists; EditOrderInFile editInFile = new EditOrderInFile(); PrintReceipt print = new PrintReceipt(); EditOrderFile editFile = new EditOrderFile(); Console.Clear(); Console.WriteLine("Edit an order"); Console.WriteLine(TextHelper.ConsoleBar); Console.WriteLine("Please enter the following information...."); Console.WriteLine(); while (true) { Console.WriteLine("Date of order: "); if (DateTime.TryParse(Console.ReadLine(), out orderDate)) { order.Date = orderDate; break; } Console.WriteLine("You did not enter a valid date format. Press any key to continue..."); Console.ReadKey(); } while (true) { lookupResponse = manager.LookupOrder(order.Date); if (lookupResponse != null) { Orders = lookupResponse.Orders; } if (lookupResponse.success) { break; } else { Console.WriteLine("An error occurred."); Console.WriteLine(lookupResponse.message); continue; } } while (true) { Console.Clear(); ConsoleIO.DisplayOrderDetails(lookupResponse.Orders); int orderNumber; Console.WriteLine("Order number: "); if (int.TryParse(Console.ReadLine(), out orderNumber)) { order.OrderNumber = orderNumber; } else { Console.WriteLine("You did not enter a number. Press any key to continue..."); Console.ReadKey(); } string filePath = FilePath.GetFilePath(order.Date); Orders = ReadOrdersFromFile.ReadOrders(filePath); orderExists = editInFile.CheckOrderNumberExists(Orders, order.OrderNumber); if (!orderExists) { Console.WriteLine("That order number does not exist for the date you entered. Press any key to continue..."); Console.ReadKey(); continue; } else { Order singleOrder = Orders.Where(ord => ord.OrderNumber == order.OrderNumber).Single(); order = singleOrder; } while (true) { print.Print(order); Console.WriteLine("Are you sure you want to delete this order? (Y/N)?"); string userInput = Console.ReadLine().ToUpper(); switch (userInput) { case "Y": RemoveOrderFile remove = new RemoveOrderFile(); remove.RemoveOrderFromList(Orders, order, order.Date); editFile.EditOrderToFile(Orders, order.Date); Console.WriteLine("Remove has been saved! Press any key to continue..."); Console.ReadKey(); break; case "N": Console.WriteLine("Remove has been canceled. Press any key to continue..."); Console.ReadKey(); break; default: Console.WriteLine("That was not a valid entry! Press any key to continue..."); Console.ReadKey(); continue; } break; } break; } }