public TaxesResponse GetTaxes() { TaxesResponse response = new TaxesResponse(); response.Success = true; response.Taxes = _taxes; return(response); }
public void CanLoadTaxes() { OrderManager manager = OrderManagerFactory.Create(); TaxesResponse response = manager.FindTaxes(); Assert.AreEqual(response.taxes.Count, 4); Assert.AreEqual(response.taxes[0].StateName, "Ohio"); Assert.AreEqual(response.taxes[0].StateAbbreviation, "OH"); Assert.AreEqual(response.taxes[1].TaxRate, 6.75M); Assert.AreEqual(response.taxes[2].StateName, "Michigan"); Assert.AreEqual(response.taxes[3].TaxRate, 6.00M); }
public TaxResponse GetTaxByState(string stateAbbr) { TaxResponse response = new TaxResponse(); try { TaxesResponse responseTs = new TaxesResponse(); responseTs = GetTaxes(); if (responseTs.Success) { StateTax statetaxToGet = responseTs.Taxes.Find(t => t.StateCode.ToUpper() == stateAbbr.ToUpper()); if (statetaxToGet == null) { response.Message = $"Was unable to find a state matching state abbreviation: {stateAbbr}!"; response.Success = false; return(response); } else { response.Success = true; response.StateTax = statetaxToGet; return(response); } } else { response.Message = responseTs.Message; response.Success = false; return(response); } } catch (FileNotFoundException) { response.Message = $"The file: {TaxesFileName} was not found. \nContact IT!"; response.Success = false; return(response); } catch (Exception ex) { throw ex; //Throw exception up to calling method for handling in catch there. } finally { } }
public TaxesResponse FindTaxes() { TaxesResponse response = new TaxesResponse(); response.taxes = _taxesRepo.LoadTax(); if (response.taxes == null) { response.Success = false; response.Message = "Taxes could not be found"; return(response); } else { response.Success = true; } return(response); }
public void CanReadTaxes() { //TaxManager myTM = TaxManagerFactory.Create(); TaxFileRepository myTR = new TaxFileRepository(_dataPath + _taxTestFile); TaxesResponse taxesResponse = new TaxesResponse(); taxesResponse = myTR.GetTaxes(); //Did it retrieve 7 taxes regions? Assert.AreEqual(7, taxesResponse.Taxes.Count()); //HI,Hawaii,4.35 StateTax stateToValidate = taxesResponse.Taxes.Find(t => t.StateCode == "HI"); Assert.AreEqual("HI", stateToValidate.StateCode); Assert.AreEqual("Hawaii", stateToValidate.StateName); Assert.AreEqual(4.35, stateToValidate.TaxRate); //RI,Rhode Island,7 stateToValidate = taxesResponse.Taxes.Find(t => t.StateCode == "RI"); Assert.AreEqual("RI", stateToValidate.StateCode); Assert.AreEqual("Rhode Island", stateToValidate.StateName); Assert.AreEqual(7, stateToValidate.TaxRate); }
internal static void Execute(DisplayMode mode) { DisplayOrderWorkFlow.Execute(mode, true, false, out OrderResponse response, out OrderManager myOM); if (!response.Success) { return; } string input; if (!ConsoleIO.GetString("Type (E/e) to edit this order: ", 1, out input)) { return; } if (input.ToUpper() == "E") { Order editedOrder = new Order() { OrderDate = response.Order.OrderDate, OrderNumber = response.Order.OrderNumber, OrderStateTax = response.Order.OrderStateTax, OrderProduct = response.Order.OrderProduct, CustomerName = response.Order.CustomerName, Area = response.Order.Area, FileTotal = response.Order.FileTotal, FileTax = response.Order.FileTax, FileMaterialCost = response.Order.FileMaterialCost, FileLaborCost = response.Order.FileLaborCost, }; ConsoleIO.DisplayText("OK, you are now in Edit mode.", false, false, ConsoleColor.DarkYellow); //Customer Name if (!ConsoleIO.GetString($"Enter a new customer name, or press Enter to keep ({editedOrder.CustomerName}): ", _maxCustNameLength, out input)) { return; } if (input == "") { //User pressed Enter } else { if (input.Length > _maxCustNameLength || !(input.All(c => char.IsLetterOrDigit(c) || c == ' ' || c == '.' || c == ','))) { bool loop; do { loop = false; ConsoleIO.DisplayText("That name was invalid. \nOnly Characters [A-Z][a-z][0-9][,][.][ ] are allowed.", false, false, ConsoleColor.Red); if (!ConsoleIO.GetString($"Enter the customer name (max {_maxCustNameLength} characters): ", _maxCustNameLength, out input)) { return; } if (input == "" || input.Length > _maxCustNameLength || !(input.All(c => char.IsLetterOrDigit(c) || c == ' ' || c == '.' || c == ','))) { loop = true; } } while (loop); } else { editedOrder.CustomerName = input; } } //State TaxManager myTM = TaxManagerFactory.Create(); TaxesResponse responseTs = myTM.GetTaxes(); if (!ConsoleIO.GetString($"Enter a new state (f.ex. {responseTs.Taxes[0].StateCode}), or press Enter to keep ({editedOrder.OrderStateTax.StateCode}): ", 2, out input)) { return; } if (input == "") { //User pressed Enter } else { TaxResponse responseT = myTM.GetTaxByState(input.ToUpper()); if (!responseT.Success) { ConsoleIO.DisplayText("That was not a valid state.", false, false, ConsoleColor.Red); ConsoleIO.DisplayTaxes(responseTs.Taxes, false, false, ConsoleColor.Blue); bool loop; do { loop = false; if (!ConsoleIO.GetString($"Enter a state (f.ex. {responseTs.Taxes[0].StateCode}) from the list: ", 2, out input)) { return; } responseT = myTM.GetTaxByState(input.ToUpper()); if (!responseT.Success) { ConsoleIO.DisplayText("That was not a valid state.", false, false, ConsoleColor.Red); loop = true; } } while (loop); editedOrder.OrderStateTax = responseT.StateTax; } else { editedOrder.OrderStateTax = responseT.StateTax; } } //Product if (!ConsoleIO.GetString($"Enter a new product type, or press Enter to keep the current one ({editedOrder.OrderProduct.ProductType}): ", 255, out input)) { return; } if (input == "") { //User pressed Enter } else { ProductManager myPM = ProductManagerFactory.Create(); ProductResponse responseP = myPM.GetProductByType(input.ToUpper()); if (!responseP.Success) { ConsoleIO.DisplayText("That was not a valid product type.", false, false, ConsoleColor.Red); ProductsResponse responsePs = myPM.GetProducts(); ConsoleIO.DisplayProducts(responsePs.Products, false, false, ConsoleColor.Blue); bool loop; do { loop = false; if (!ConsoleIO.GetString("Enter the product type from the list wish to select: ", 255, out input)) { return; } responseP = myPM.GetProductByType(input.ToUpper()); if (!responseP.Success) { ConsoleIO.DisplayText("That was not a valid product type.", false, false, ConsoleColor.Red); loop = true; } } while (loop); editedOrder.OrderProduct = responseP.Product; } else { editedOrder.OrderProduct = responseP.Product; } } //Area decimal decimalArea = editedOrder.Area; if (!ConsoleIO.GetString($"Enter a new area (>={_minArea} ft²), or press Enter to keep the current area ({editedOrder.Area}): ", 255, out input)) { return; } if (input == "") { //User pressed Enter } else { if (!(decimal.TryParse(input, out decimalArea)) || decimalArea < _minArea || decimalArea > _maxArea) { if (!ConsoleIO.GetDecimalValue($"Enter a valid Area (>={_minArea} ft²) : ", true, _minArea, _maxArea, out decimalArea)) { return; } editedOrder.Area = decimalArea; } else { editedOrder.Area = decimalArea; } } editedOrder.Recalculate(); //Display Confirmation of Order Changes Console.Clear(); ConsoleIO.DisplayText("Original order:", false, false, ConsoleColor.Blue); ConsoleIO.DisplayOrder(mode, response.Order, false, false, ConsoleColor.Blue); ConsoleIO.DisplayText("Edited order:", false, false, ConsoleColor.DarkYellow); ConsoleIO.DisplayOrder(mode, editedOrder, false, false, ConsoleColor.DarkYellow); //Prompt for Saving if (!ConsoleIO.GetString("Press (Y/y) if you wish to save the changes: ", 1, out input)) { return; } if (input.ToUpper() == "Y") { OrderResponse editResponse = new OrderResponse(); editResponse = myOM.EditOrder(editedOrder); if (editResponse.Success) { ConsoleIO.DisplayText("Changes were saved. \nPress any key to continue...", false, true); } else { ConsoleIO.DisplayText(editResponse.Message + "\nPress any key to continue...", false, true, ConsoleColor.Red); } } else { ConsoleIO.DisplayText("Changes were NOT saved. \nPress any key to continue...", false, true); } } }
internal static void Execute(DisplayMode mode) { Order newOrder = new Order(); ConsoleIO.DisplayText("===== Add Order =============================================", true, false); if (!ConsoleIO.GetDateValue("Enter the date you wish create an order for: ", DateTime.Now.Date, out DateTime orderDate)) { return; } newOrder.OrderDate = orderDate; //Customer Name string customerName; bool loop; do { loop = false; if (!ConsoleIO.GetString($"Enter the customer name (max {_maxCustNameLength} characters): ", _maxCustNameLength, out customerName)) { return; } //if (!(customerName.All(c => char.IsLetterOrDigit(c) || c == '.' || c == ','))) if (customerName == "" || customerName.Length > _maxCustNameLength || !(customerName.All(c => char.IsLetterOrDigit(c) || c == ' ' || c == '.' || c == ','))) { ConsoleIO.DisplayText("The name entered contains invalid characters. \nOnly Characters [A-Z][a-z][0-9][,][.][ ] are allowed!", false, false, ConsoleColor.Red); loop = true; } } while (loop); newOrder.CustomerName = customerName; //State String input; TaxManager myTM = TaxManagerFactory.Create(); TaxesResponse responseTs = myTM.GetTaxes(); ConsoleIO.DisplayTaxes(responseTs.Taxes, false, false, ConsoleColor.Blue); TaxResponse responseT = new TaxResponse(); do { loop = false; if (!ConsoleIO.GetString($"Enter a state (f.ex. {responseTs.Taxes[0].StateCode}) from the list: ", 2, out input)) { return; } responseT = myTM.GetTaxByState(input); if (!responseT.Success) { ConsoleIO.DisplayText("That was not a valid state.", false, false, ConsoleColor.Red); loop = true; } } while (loop); newOrder.OrderStateTax = responseT.StateTax; //Product ProductManager myPM = ProductManagerFactory.Create(); ProductsResponse responsePs = myPM.GetProducts(); ConsoleIO.DisplayProducts(responsePs.Products, false, false, ConsoleColor.Blue); ProductResponse responseP = new ProductResponse(); do { loop = false; if (!ConsoleIO.GetString("Enter the product type from the list wish to select: ", 255, out input)) { return; } responseP = myPM.GetProductByType(input); if (!responseP.Success) { ConsoleIO.DisplayText("That was not a valid product type.", false, false, ConsoleColor.Red); loop = true; } } while (loop); newOrder.OrderProduct = responseP.Product; //Area if (!ConsoleIO.GetDecimalValue($"Enter a valid Area (>={_minArea} ft²) : ", true, _minArea, _maxArea, out decimal decimalArea)) { return; } newOrder.Area = decimalArea; newOrder.Recalculate(); //Display Confirmation of Order Changes Console.Clear(); ConsoleIO.DisplayText("New order:", false, false, ConsoleColor.DarkYellow); ConsoleIO.DisplayOrder(mode, newOrder, false, false, ConsoleColor.DarkYellow); //Prompt for Saving if (!ConsoleIO.GetString($"Press (Y/y) if you wish to save this new order.", 1, out input)) { return; } if (input.ToUpper() == "Y") { OrderManager myOM = OrderManagerFactory.Create(orderDate); OrderResponse response = new OrderResponse(); response = myOM.AddOrder(newOrder); if (response.Success) { ConsoleIO.DisplayText("The order was saved. \nPress any key to continue...", false, true); } else { ConsoleIO.DisplayText(response.Message + "\nPress any key to continue...", false, true, ConsoleColor.Red); } } else { ConsoleIO.DisplayText("The order was NOT saved. \nPress any key to continue...", false, true); } }
public void Execute() { Console.Clear(); OrderManager manager = OrderManagerFactory.Create(); TaxesResponse taxResponse = manager.FindTaxes(); ProductResponse prodResponse = manager.FindProducts(); Console.WriteLine(" Edit Order "); Console.WriteLine("--------------------------------"); DateTime orderDatedit = ConsoleIO.GetOrderDate(); int orderNumber = ConsoleIO.GetOrderNumber(orderDatedit); OrderLookupResponse selectOrder = manager.FindSelectOrder(orderNumber, orderDatedit); if (selectOrder.Success == false) { Console.WriteLine($"An error occurred: {selectOrder.Message}"); } else { Order editOrder = selectOrder.IndivOrder; editOrder.OrderDate = orderDatedit; ConsoleIO console = new ConsoleIO(); Console.WriteLine($"\nEnter Customer Name({editOrder.CustomerName}): "); string editedName = console.GetEditedName(editOrder); editedName = editOrder.CustomerName; Console.WriteLine("\nHere is the list of available states: "); ConsoleIO.DisplayTaxes(taxResponse.taxes); Console.WriteLine($"\nEnter a State ({editOrder.State}): "); string editedState = console.GetEditedState(editOrder, taxResponse.taxes); editOrder.State = editedState; ConsoleIO.ApplyTax(taxResponse.taxes, editOrder); Console.WriteLine("\nAvailable Product Types: "); ConsoleIO.DisplayProducts(prodResponse.products); Console.WriteLine($"\nEnter a Product Type ({editOrder.ProductType}): "); string editedProduct = console.GetEditedProduct(editOrder, prodResponse.products); editOrder.ProductType = editedProduct; ConsoleIO.ApplyProduct(prodResponse.products, editOrder); Console.WriteLine($"\nCurrent area ({editOrder.Area})"); decimal area = ConsoleIO.GetEditedArea(editOrder); editOrder.Area = area; PutitAllTogether(editOrder); ConsoleIO.DisplayOneOrder(editOrder); string YayOrNay = ConsoleIO.GetYesorNo(); if (YayOrNay.ToUpper() == "Y") { OrderLookupResponse resp = manager.editOrder(editOrder, editOrder.OrderDate); if (resp.Success == true) { Console.WriteLine($"Order Number {editOrder.OrderNumber} has been changed"); } } else if (YayOrNay.ToUpper() == "N") { Console.WriteLine("\nEdits are cancelled"); Console.WriteLine("\nPress any key to continue"); Console.ReadKey(); } else if (YayOrNay.Length > 1 || YayOrNay.Length < 1) { ConsoleIO.GetYesorNo(); } } Console.WriteLine("\nPress any key to continue"); Console.ReadKey(); }
public TaxesResponse GetTaxes() { TaxesResponse response = new TaxesResponse(); response.Success = true; //Assume true, failed parsing turns this false! try { if (TaxesFileName.Length == 0) { response.Message = $"The file {TaxesFileName} could be found."; response.Success = false; return(response); } using (StreamReader sr = new StreamReader(TaxesFileName)) { string line; //Get the header line = sr.ReadLine(); //Does the file contain data? if (line == null) { response.Message = $"The file {TaxesFileName} is empty. \nContact IT!"; response.Success = false; return(response); } else { //Evaluate Header Response headerResponse = new Response(); headerResponse = ValidateHeader(line); //ONLY EVALUATES HEADER IF _evalHeader == true if (!headerResponse.Success) { response.Message = headerResponse.Message; response.Success = false; return(response); } } //OK to parse file for data!! int lineNR = 0; while ((line = sr.ReadLine()) != null) { if (line == "") { continue; //Empty line in the file, skip it... } lineNR++; //Parse the line from the file TaxResponse parseTaxLineResponse = new TaxResponse(); parseTaxLineResponse = ParseTaxLine(line, lineNR); if (!parseTaxLineResponse.Success) { response.Message = parseTaxLineResponse.Message; response.Success = false; } else { response.Taxes.Add(parseTaxLineResponse.StateTax); //Success true by default - no need to update when orderReadSuccess... } } if (!response.Success && response.Message.Length > 2) { response.Message = response.Message.Substring(0, response.Message.Length - 2); //Remove last "\n" //response.Success is already set to false! } return(response); //If there were errors reading lines, these lines will have been omitted during reading, and error messages generated explaining this. //StateTax lines parsed w/o errors are added to the List, which can be used if so desired (in spite of the !Success result). } } catch (FileNotFoundException) { response.Message = $"The file: {TaxesFileName} was not found. \nContact IT!"; response.Success = false; return(response); } catch (Exception ex) { throw ex; //Throw exception up to calling method for handling in catch there. } finally { } }
public void Execute() { OrderManager manager = OrderManagerFactory.Create(); Order newishOrder = new Order(); TaxesResponse taxresponse = manager.FindTaxes(); ProductResponse prodresponse = manager.FindProducts(); Console.Clear(); Console.WriteLine(" Add an order"); Console.WriteLine("***************************"); DateTime orderDate = ConsoleIO.GetFutureOrderDate(); string CustieName = ConsoleIO.GetAddInput(); Console.WriteLine("\nHere is the list of approved States: "); ConsoleIO.DisplayTaxes(taxresponse.taxes); Console.WriteLine("Enter State Name: "); string Appliedstate = ConsoleIO.GetAddState(taxresponse.taxes); newishOrder.State = Appliedstate; newishOrder.OrderDate = orderDate; newishOrder.CustomerName = CustieName; ConsoleIO.ApplyTax(taxresponse.taxes, newishOrder); Console.WriteLine("\nHere are the available product types: "); ConsoleIO.DisplayProducts(prodresponse.products); Console.WriteLine("\nPlease choose your product: "); string productType = ConsoleIO.GetAddProduct(prodresponse.products); newishOrder.ProductType = productType; ConsoleIO.ApplyProduct(prodresponse.products, newishOrder); int area = ConsoleIO.GetArea(); newishOrder.Area = area; PutitAllTogether(newishOrder); ConsoleIO.DisplayOneOrder(newishOrder); string userAnswer = ConsoleIO.GetYesorNo(); if (userAnswer.ToUpper() == "Y") { AddOrderResponse addResponse = manager.addOrder(newishOrder, newishOrder.OrderDate); if (addResponse.Success) { Console.WriteLine("The order has been added."); } else { Console.WriteLine("Please try again. An error occurred"); } } else { Console.WriteLine("The order was cancelled"); Console.WriteLine("Press any key to continue"); Console.ReadKey(); } Console.WriteLine("Press any key to continue"); Console.ReadKey(); }