public void AddOrder() { OrderOperations orderOps = new OrderOperations(); CustomerInput custIn = new CustomerInput(); bool isValidName = false; Console.Clear(); Console.WriteLine("Add Order"); Console.WriteLine("***************************\n"); while (!isValidName) { Console.Write("Please enter the customer name: "); custIn.CustName = Console.ReadLine(); isValidName = !string.IsNullOrEmpty(custIn.CustName); } bool isValidState = false; while (!isValidState) { Console.Write("\nPlease enter a state: "); custIn.State = Console.ReadLine().ToUpper(); TaxRateOperations taxOps = new TaxRateOperations(); if (taxOps.IsAllowedState(custIn.State)) { Console.WriteLine("\nThat is a valid state"); TaxRate rate = taxOps.GetTaxRateFor(custIn.State); isValidState = true; Console.WriteLine("\nThe tax rate for {0} is {1:p}", rate.State, rate.TaxPercent); } else { Console.WriteLine("\nThat is not a valid state"); } } bool isValidProduct = false; while (!isValidProduct) { Console.Write("\nPlease enter a product type: "); custIn.ProductType = Console.ReadLine(); ProductOperations prodOps = new ProductOperations(); if (prodOps.IsExistingProduct(custIn.ProductType)) { Console.WriteLine("\nThat is a valid product."); Product prod = prodOps.GetProductFor(custIn.ProductType); isValidProduct = true; } else { Console.WriteLine("\nThat is not one of our products."); } } bool isValidArea = false; while (!isValidArea) { Console.Write("\nPlease enter flooring area in square feet: "); decimal floorArea; bool isDecimal = decimal.TryParse(Console.ReadLine(), out floorArea); if (isDecimal) { isValidArea = true; custIn.Area = floorArea; } } Console.Write("\nReady to create new order? Y/N "); if (Console.ReadLine().ToUpper() == "N") { MenuDisplay(); } custIn.OrderNumber = 0; DateTime orderDate = default(DateTime); orderOps.CreateNewOrder(custIn, orderDate); Console.WriteLine("\nOk, your order has been created!"); Console.ReadLine(); }
public void EditOrder() { Console.Clear(); Console.WriteLine("Edit Order"); Console.WriteLine("***************************\n"); bool validDate = false; DateTime orderDate = new DateTime(); int orderNumber = 0; while (!validDate) { Console.Write("Enter a date (MM/DD/YYYY): "); validDate = DateTime.TryParse(Console.ReadLine(), out orderDate); if (!validDate) { Console.WriteLine("\nInvalid Date"); } } OrderOperations orderOperations = new OrderOperations(); OrdersResult result = orderOperations.RetrieveOrdersFor(orderDate); bool validEntry = false; if (result.Success) { while (!validEntry) { bool validNumber = false; while (!validNumber) { Console.Write("\nPlease enter an order number: "); validNumber = int.TryParse(Console.ReadLine(), out orderNumber); if (!validNumber) { Console.WriteLine("\nInvalid order number"); } else { bool reply = orderOperations.CheckIfExistingOrder(orderNumber, orderDate); if (reply) { validEntry = true; } else { Console.WriteLine("\nThere is no order for that number on that date!"); } } } } Order fullOrder = orderOperations.RetrieveOrderByNumber(orderNumber, orderDate); TaxRateOperations taxOps = new TaxRateOperations(); ProductOperations prodOps = new ProductOperations(); CustomerInput editedOrder = new CustomerInput() { CustName = fullOrder.CustomerName, Area = fullOrder.Area, ProductType = fullOrder.ProductType, State = fullOrder.State, OrderNumber = fullOrder.OrderNumber }; Console.WriteLine("\n{0} {1} {2} {3}", editedOrder.CustName, editedOrder.State, editedOrder.ProductType, editedOrder.Area); bool validName = false; string input; while (!validName) { Console.Write("\nPlease enter new Customer Name, or press enter key to skip: "); input = Console.ReadLine(); if (input != "") { editedOrder.CustName = input; validName = true; } else { validName = true; } } bool validState = false; while (!validState) { Console.Write("\nPlease enter new State, or press enter key to skip: "); input = Console.ReadLine().ToUpper(); if (input != "") { if (taxOps.IsAllowedState(input)) { editedOrder.State = input; validState = true; } else { Console.Write("\nThat is not a valid state"); } } else { validState = true; } } bool validProduct = false; while (!validProduct) { Console.Write("\nPlease enter new Product Type, or press enter key to skip: "); input = Console.ReadLine().ToUpper(); if (input != "") { if (prodOps.IsExistingProduct(input)) { editedOrder.ProductType = input; validProduct = true; } else { Console.Write("\nThat is not one of our products"); } } else { validProduct = true; } } bool validArea = false; while (!validArea) { Console.Write("\nPlease enter new Area in square feet, or press enter key to skip: "); input = Console.ReadLine(); if (input != "") { decimal userChoice; bool isDecimal = decimal.TryParse(input, out userChoice); if (isDecimal) { editedOrder.Area = userChoice; validArea = true; } else { Console.WriteLine("\nThat is not a valid number"); } } else { validArea = true; } } Console.Write("\nAre you ready to save edited order details? Y/N "); if (Console.ReadLine().ToUpper() == "N") { MenuDisplay(); } else { orderOperations.CreateNewOrder(editedOrder, orderDate); Order newEditedOrder = orderOperations.RetrieveOrderByNumber(orderNumber, orderDate); Console.Clear(); Console.Write("\nYour order has been edited:\n"); Console.WriteLine("\n{0} {1} {2} {3} {4} {5} {6:c} {7:c} {8:c} {9:c} {10:c} {11:c}", newEditedOrder.OrderNumber, newEditedOrder.CustomerName, newEditedOrder.State, newEditedOrder.TaxRate, newEditedOrder.ProductType, newEditedOrder.Area, newEditedOrder.CostPerSquareFoot, newEditedOrder.LaborCostPerSquareFoot, newEditedOrder.MaterialCost, newEditedOrder.LaborCost, newEditedOrder.Tax, newEditedOrder.Total); Console.Write("\nPress Enter to return to the Main Menu"); Console.ReadLine(); } } else { Console.WriteLine("\nUnable to display orders: {0}", result.Message); } }
public void Execute() { //bool correctData = false; //do //{ string name = GetNameForOrder(); string state = GetStateForOrder(); string productType = GetProductTypeForOrder(); decimal area = GetAreaForOrder(); ProductOperations po = new ProductOperations(); OrderOperations addOrderOperations = new OrderOperations(OrderRepositoryFactory.CreateOrderRepository()); StateOperations so = new StateOperations(); State stateInformation = new State(); Product ProductInfornmation = po.GetProductByName(productType); stateInformation = so.GetStateByName(state); decimal MaterialCost = area * ProductInfornmation.MaterialCostPerSqFoot; decimal LaborCost = area * ProductInfornmation.LaborCostPerSqFoot; decimal TaxTotal = (LaborCost + MaterialCost) * (stateInformation.TaxRate / 100); decimal OrderTotal = MaterialCost + LaborCost + TaxTotal; Order newOrder = new Order() { // OrderNumber = newOrderNumber, CustomerName = name, DateTime = DateTime.Now.ToShortDateString(), State = state, TaxRate = stateInformation.TaxRate, ProductType = ProductInfornmation.ProductType, Area = area, MaterialCostPerSqFt = ProductInfornmation.MaterialCostPerSqFoot, LaborCostPerSqFt = ProductInfornmation.LaborCostPerSqFoot, TotalMaterialCost = MaterialCost, TotalLaborCost = LaborCost, TotalTaxCost = TaxTotal, TotalOrderCost = OrderTotal }; bool isValid = false; string confirm = ""; while (!isValid) { DisplayNewOrder(MaterialCost, LaborCost, TaxTotal, OrderTotal, newOrder); Console.WriteLine(); Console.WriteLine("Is all the information correct?"); Console.WriteLine("Enter (Y) or (N)"); confirm = Console.ReadLine().ToUpper(); if (string.IsNullOrEmpty(confirm)) { isValid = false; Console.WriteLine("Please enter (Y) or (N)"); Console.WriteLine("Press ENTER to continue"); Console.ReadLine(); } else if ((confirm != "N") && (confirm != "Y")) { isValid = false; Console.WriteLine("{0} is not a \"Y\" or \"N\"", confirm); Console.WriteLine("Press ENTER to continue"); Console.ReadLine(); } else { isValid = true; } } if (confirm == "Y") { var test = addOrderOperations.CreateNewOrder(newOrder); if (test.IsValid) { Console.Clear(); Console.WriteLine(); Console.WriteLine("your order was added"); Console.WriteLine(); Console.WriteLine("The order number is {0}", newOrder.OrderNumber); Console.WriteLine("The date of the order is {0}", newOrder.DateTime); Console.WriteLine(); Console.WriteLine("Press ENTER to Continue."); Console.ReadLine(); } } }