public Order GenerateOrderInfo(int ordernumber, string customername, string state, string producttype, decimal area) { Order order = new Order(); Tax tax = _taxRepository.LoadTax(state); Product product = _productRepository.LoadProduct(producttype); order.OrderNumber = ordernumber; order.CustomerName = customername; order.State = state; order.ProductType = producttype; order.Area = area; order.TaxRate = tax.TaxRate; order.CostPerSquareFoot = product.CostPerSquareFoot; order.LaborCostPerSquareFoot = product.LaborCostPerSquareFoot; 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); return(order); }
public void Execute() { OrderManager manager = OrderManagerFactory.Create(); Console.Clear(); Console.WriteLine("Edit an order"); Console.WriteLine("------------------------"); bool isValidDate = false; DateTime orderDate = new DateTime(); string date1 = ""; while (isValidDate == false) { date1 = io.GetDateFromUser("Please provide a date"); orderDate = DateTime.ParseExact(date1, "MMddyyyy", CultureInfo.GetCultureInfo("en-us")); if (orderDate <= DateTime.Today) { Console.WriteLine("Date must be later than today"); } else { isValidDate = true; } } DisplayOrderResponse response = manager.LoadOrders(date1); foreach (FlooringOrder order in response.Orders) { io.DisplayOrderDetails(order); } int ordernumber = -1; bool isValidNumber = false; while (isValidNumber == false) { string orderstring = io.GetStringFromUser("Please enter an order number."); if (!int.TryParse(orderstring, out ordernumber)) { Console.WriteLine("This did not work, please enter a number"); } else { foreach (var item in response.Orders) { if (item.OrderNumber == ordernumber) { newOrder = item; } } isValidNumber = true; } } Console.WriteLine(""); string newName = PromptUser("What would you like to change your name to?"); if (newName != "") { while (!newName.All(c => Char.IsLetterOrDigit(c) || c == ',' || c == '_' || c == '.')) { Console.WriteLine("Names must include either letters, numbers, spaces, periods, or commas (or any combonation thereof)"); newName = PromptUser("What is your name?"); } newOrder.CustomerName = newName; } TaxStateResponse taxResponse = uo.LoadTax(); FlooringTax orderTax = new FlooringTax(); bool isValidTax = false; while (isValidTax == false) { foreach (FlooringTax tax in taxResponse.TaxRate) { Console.WriteLine(" " + (taxResponse.TaxRate.IndexOf(tax) + 1) + ". " + tax.StateAbbreviation); } Console.WriteLine("Order is currently in " + newOrder.State); string newState = PromptUser("Enter a new state or press enter to continue."); if (newState != "") { if (int.TryParse(newState, out int nation)) { if (nation > 0 && nation <= taxResponse.TaxRate.Count) { newOrder.State = taxResponse.TaxRate[nation - 1].StateAbbreviation; newOrder.TaxRate = taxResponse.TaxRate[nation - 1].TaxRate; isValidTax = true; } } else { Console.WriteLine("That state isn't in our region yet."); } } else { isValidTax = true; } } List <FlooringProduct> ProductList = yo.LoadProducts(); FlooringProduct orderProduct = new FlooringProduct(); bool isValidProduct = false; while (isValidProduct == false) { foreach (FlooringProduct prod in ProductList) { Console.Write(" " + (ProductList.IndexOf(prod) + 1) + ". " + prod.ProductType); Console.Write(" Cost per sqft $" + prod.CostPerSquareFoot); Console.Write(" Cost for Labor per sqft $" + prod.LaborCostPerSquareFoot); Console.WriteLine("\n"); } Console.WriteLine("You have already chosen " + newOrder.ProductType); string newProduct = PromptUser("Please specifiy a different product or press enter to continue"); if (newProduct != "") { if (int.TryParse(newProduct, out int supply)) { if (supply > 0 && supply <= ProductList.Count) { newOrder.ProductType = ProductList[supply - 1].ProductType; newOrder.LaborCostPerSquareFoot = ProductList[supply - 1].LaborCostPerSquareFoot; newOrder.CostPerSquareFoot = ProductList[supply - 1].CostPerSquareFoot; isValidProduct = true; } } else { Console.WriteLine("That product isn't available yet."); } } else { isValidProduct = true; } } decimal area1 = 0; bool isValidArea = false; while (isValidArea == false) { area1 = newOrder.Area; string area = PromptUser("Please enter a new area or press enter to continue"); if (area != "") { if (decimal.TryParse(area, out area1)) { if (area1 < 100) { Console.WriteLine("You must enter a positive amount above 100"); Console.WriteLine("Please enter a valid square footage."); } else { newOrder.Area = area1; isValidArea = true; } } } else { isValidArea = true; } } //ask user for order number //if order exisits - ask user for each piece of order data && display exisiting data //if user presses Enter key without entering data - leave existing data in place //Only CustomerName, State, ProductType, Area can be changed //Order date may NOT change Console.Clear(); io.DisplayOrderDetails(newOrder); bool isSave = false; while (isSave == false) { string place = PromptUser("Would you like to place this order? Please enter yes or no"); if (place.ToLower() == "yes") { EditOrderResponse editResponse = manager.EditOrder(date1, newOrder); //still saving the new file even if selecting no isSave = true; // save final to file with approp date } else if (place.ToLower() == "no") { isSave = true; //return to main menu } else { Console.WriteLine("Please enter yes or no"); } } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
public SaveOrderResponse SaveOrder( string stringOrderDate, string customerName, string state, string productType, string area) { SaveOrderResponse response = new SaveOrderResponse(); DateTime orderDate; if (!DateTime.TryParseExact(stringOrderDate, "ddMMyyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out orderDate)) { response.Success = false; response.Message = ($"{stringOrderDate} is not a valid date."); return(response); } if (orderDate.Date <= DateTime.Today) { response.Success = false; response.Message = "The Order Date must be later than today. "; return(response); } else if (customerName == "") { response.Success = false; response.Message = "The Customer Name must not be blank."; return(response); } else if (taxRep.LoadTax(state) == null) { response.Success = false; response.Message = $"There is no tax rate for {state}."; return(response); } else if (productRep.LoadProduct(productType) == null) { response.Success = false; response.Message = $"There is no {productType} Product Type."; return(response); } else { response.Success = true; Tax tax = taxRep.LoadTax(state); Product product = productRep.LoadProduct(productType); decimal taxRate = Convert.ToDecimal(tax.TaxRate); decimal areaDecimal = Convert.ToDecimal(area); decimal material = areaDecimal * product.CostPerSquareFoot; decimal labor = areaDecimal * product.LaborCostPerSquareFoot; decimal taxTotal = ((material + labor) * (taxRate / 100)); decimal total = material + labor + taxTotal; Order order = new Order { OrderNumber = GetOrderNumber(stringOrderDate), CustomerName = customerName, State = state, TaxRate = taxRate, ProductType = productType, Area = Convert.ToInt16(area), CostPerSquareFoot = product.CostPerSquareFoot, LaborCostPerSquareFoot = product.LaborCostPerSquareFoot, MaterialCost = material, LaborCost = labor, Tax = taxTotal, Total = total }; response.Order = order; _orderRepository.AddOrder(response.Order, stringOrderDate); } return(response); }
public void Execute() { OrderManager manager = OrderManagerFactory.Create(); Console.Clear(); Console.WriteLine("Add an order"); Console.WriteLine("------------------------"); bool isValidDate = false; DateTime orderDate = new DateTime(); string date1 = ""; while (isValidDate == false) { date1 = io.GetDateFromUser("Please provide a date"); orderDate = DateTime.ParseExact(date1, "MMddyyyy", CultureInfo.GetCultureInfo("en-us")); if (orderDate < DateTime.Today) { Console.WriteLine("Date must be after today"); } else { isValidDate = true; } } // orderNumberResponse = manager.NextOrderNumber(date1); string name = PromptUser("What is your name?"); while (!name.All(c => Char.IsLetterOrDigit(c) || c == ',' || c == '_' || c == '.') || name.Trim() == "") { Console.WriteLine("Names must include either letters, numbers, spaces, periods, or commas (or any combonation thereof)"); name = PromptUser("What is your name?"); } TaxStateResponse taxResponse = uo.LoadTax(); FlooringTax orderTax = new FlooringTax(); bool isValidTax = false; while (isValidTax == false) { foreach (FlooringTax tax in taxResponse.TaxRate) { Console.WriteLine(" " + (taxResponse.TaxRate.IndexOf(tax) + 1) + ". " + tax.StateAbbreviation); } string state = PromptUser("Please specify the number of the state you're planning on building in."); if (int.TryParse(state, out int nation)) { if (nation > 0 && nation <= taxResponse.TaxRate.Count) { orderTax = taxResponse.TaxRate[nation - 1]; isValidTax = true; } } else { Console.WriteLine("That state isn't in our region yet."); } } List <FlooringProduct> ProductList = yo.LoadProducts(); FlooringProduct orderProduct = new FlooringProduct(); bool isValidProduct = false; while (isValidProduct == false) { foreach (FlooringProduct prod in ProductList) { Console.Write(" " + (ProductList.IndexOf(prod) + 1) + ". " + prod.ProductType); Console.Write(" Cost per sqft $" + prod.CostPerSquareFoot); Console.Write(" Cost for Labor per sqft $" + prod.LaborCostPerSquareFoot); Console.WriteLine("\n"); } string product = PromptUser("Please specify which product you would like to use."); if (int.TryParse(product, out int supply)) { if (supply > 0 && supply <= ProductList.Count) { orderProduct = ProductList[supply - 1]; isValidProduct = true; } } else { Console.WriteLine("That product isn't available yet."); } } //Need to select product, if not (product) then show an error and loop string area = PromptUser("What is the square footage of the area you are looking to cover?"); decimal area1; while (decimal.TryParse(area, out area1) && area1 < 100) { //if (area1 < 100) //{ Console.WriteLine("You must enter a positive amount above 100"); Console.WriteLine("Please enter a valid square footage."); area = PromptUser("What is the square footage of the area you are looking to cover?"); //} //else //{ // area = area1.ToString(); //} } Console.Clear(); Console.WriteLine(""); newOrder.Area = area1; newOrder.State = orderTax.StateAbbreviation; newOrder.TaxRate = orderTax.TaxRate; newOrder.CustomerName = name; newOrder.date = orderDate; newOrder.ProductType = orderProduct.ProductType; newOrder.CostPerSquareFoot = orderProduct.CostPerSquareFoot; newOrder.LaborCostPerSquareFoot = orderProduct.LaborCostPerSquareFoot; io.DisplayOrderDetails(newOrder); bool isSave = false; while (isSave == false) { string place = PromptUser("Would you like to place this order? Please enter yes or no"); if (place.ToLower() == "yes") { AddOrderResponse addResponse = manager.AddOrder(date1, newOrder); isSave = true; // save final to file with approps date } else if (place.ToLower() == "no") { isSave = true; //return to main menu } else { Console.WriteLine("Please enter yes or no"); } } Console.WriteLine("Press any key to continue..."); Console.ReadLine(); string PromptUser(string s) { Console.WriteLine(s); return(Console.ReadLine()); } }
public Tax GetStateTax(string state) { return(_taxRepository.LoadTax().FirstOrDefault(t => t.StateAbbreviation == state || t.StateName == state)); }