public void CanGetStateTaxFromFile(string stateName, bool expected) { StateTaxManager taxManager = StateTaxManagerFactory.Create(); StateLookupResponse response = taxManager.GetStateTax(stateName); Assert.AreEqual(expected, response.Success); }
public static StateTaxResponse CreateStateTax(string stateAbbreviation) { StateTaxManager manager = StateTaxManagerFactory.Create(); StateTaxResponse stResponse = manager.GetStateTax(stateAbbreviation); if (stResponse.Success) { return(stResponse); } else { Console.WriteLine("An error occured: "); Console.WriteLine(stResponse.Message); } return(stResponse); }
public void Execute() { Console.Clear(); ConsoleIO.HeadingLable("Add an Order"); Order newOrder = new Order(); newOrder.OrderDate = ConsoleIO.GetDateFromUser("Enter Order Date (ex. MM/DD/YYYY): "); newOrder.CustomerName = ConsoleIO.GetStringInputFromUser("Customer Name: "); StateTaxManager stateTaxManager = StateTaxManagerFactory.Create(); bool validState = false; while (!validState) { StateLookupResponse response = stateTaxManager.GetStateTax(ConsoleIO.GetStringInputFromUser("State (ex. MN, or Minnesota): ")); if (response.Success) { newOrder.State = response.StateTax.StateAbbreviation; newOrder.TaxRate = response.StateTax.TaxRate; validState = true; } else { ConsoleIO.RedMessage($"An Error Occured: {response.Message}"); } } ProductManager productManager = ProductManagerFactory.Create(); ProductListResponse productList = productManager.GetProductList(); if (productList.Success) { ConsoleIO.HeadingLable("Product List"); foreach (Product p in productList.Products) { ConsoleIO.DisplayProducts(p); } } else { ConsoleIO.RedMessage($"An Error Occured: {productList.Message}"); Console.WriteLine("\nPress any key to continue..."); Console.ReadKey(); return; } bool validProduct = false; while (!validProduct) { ProductLookupResponse response = productManager.GetProduct(ConsoleIO.GetStringInputFromUser("Product Name: ")); if (response.Success) { newOrder.ProductType = response.Product.ProductType; newOrder.CostPerSquareFoot = response.Product.CostPerSquareFoot; newOrder.LaborCostPerSquareFoot = response.Product.LaborCostPerSquareFoot; validProduct = true; } else { ConsoleIO.RedMessage($"An Error Occured: {response.Message}"); } } newOrder.Area = ConsoleIO.GetAreaFromUser("Area: "); ConsoleIO.HeadingLable($"{newOrder.CustomerName}'s New Order"); ConsoleIO.DisplayOrderInformation(newOrder, false); OrderManager orderManager = OrderManagerFactory.Create(); bool submit = ConsoleIO.GetYesNoAnswerFromUser("Would you like to submit this order?"); if (submit) { AddOrderResponse addResponse = orderManager.AddOrder(newOrder); if (addResponse.Success) { Console.Clear(); ConsoleIO.YellowMessage("Order Submitted!"); ConsoleIO.DisplayOrderInformation(addResponse.Order, true); } else { ConsoleIO.RedMessage($"An Error Occured: {addResponse.Message}"); } } else { ConsoleIO.RedMessage("Add order cancelled."); } Console.WriteLine("\nPress any key to continue..."); Console.ReadKey(); }
public void Execute() { Console.Clear(); ConsoleIO.HeadingLable("Edit an Order"); //Get an order with an Order Number and Order Date int orderNumber = ConsoleIO.GetIntInputFromUser("Order Number: "); DateTime orderDate = ConsoleIO.GetDateFromUser("Order Date (MM/DD/YYYY): ", true); //Lookup Order and Begin editing or Error out OrderManager orderManager = OrderManagerFactory.Create(); OrderLookupResponse orderLookup = orderManager.LookupOrder(orderNumber, orderDate); if (orderLookup.Success) { //Create a new order for the user to fill in params Order editOrder = new Order(); //Display the order that will be edited ConsoleIO.HeadingLable($"Editing Order: {orderLookup.Order.OrderNumber} - {orderLookup.Order.OrderDate:MM/dd/yyyy}"); //Get new order name from user, display the old name editOrder.CustomerName = ConsoleIO.GetStringInputFromUser($"Customer Name ({orderLookup.Order.CustomerName}): ", true); //Create a state tax object to get correct input from user for new order state params StateTaxManager stateTaxManager = StateTaxManagerFactory.Create(); bool validInput = false; while (!validInput) { //Get a state tax object that matches the user input unless input is "" StateLookupResponse stateTaxResponse = stateTaxManager.GetStateTax(ConsoleIO.GetStringInputFromUser($"State (ex. MN, or Minnesota)({orderLookup.Order.State}): ", true)); if (!stateTaxResponse.Success && stateTaxResponse.Message == "") { validInput = true; } else if (stateTaxResponse.Success) { //If tax object exists assign new order state and tax params editOrder.State = stateTaxResponse.StateTax.StateAbbreviation; editOrder.TaxRate = stateTaxResponse.StateTax.TaxRate; validInput = true; } else { ConsoleIO.RedMessage($"An Error Occured: {stateTaxResponse.Message}"); } } //Create a product manager to get a product list ProductManager productManager = ProductManagerFactory.Create(); ProductListResponse productList = productManager.GetProductList(); //Print out product list or error out if (productList.Success) { ConsoleIO.HeadingLable("Product List"); foreach (Product p in productList.Products) { ConsoleIO.DisplayProducts(p); } } else { ConsoleIO.RedMessage($"An Error Occured: {productList.Message}"); Console.WriteLine("\nPress any key to continue..."); Console.ReadKey(); return; } //Get valid user input for new order product type bool validProduct = false; while (!validProduct) { ProductLookupResponse productResponse = productManager.GetProduct(ConsoleIO.GetStringInputFromUser($"Product Name ({orderLookup.Order.ProductType}): ", true)); //User enters nothing and nothing is assigned if (!productResponse.Success && productResponse.Message == "") { validProduct = true; } else if (productResponse.Success) { //Valid entry assigns new order product params editOrder.ProductType = productResponse.Product.ProductType; editOrder.CostPerSquareFoot = productResponse.Product.CostPerSquareFoot; editOrder.LaborCostPerSquareFoot = productResponse.Product.LaborCostPerSquareFoot; validProduct = true; } else { ConsoleIO.RedMessage($"An Error Occured: {productResponse.Message}"); } } //Get valid area for new order from user editOrder.Area = ConsoleIO.GetAreaFromUser($"Area ({orderLookup.Order.Area}): ", true); //Assign old order params to new order params EditOrderResponse editResponse = orderManager.EditOrder(orderLookup.Order, editOrder); //If the edit is successful ask to save order, otherwise error out if (editResponse.Success) { //Display ConsoleIO.HeadingLable("Updated Order"); ConsoleIO.DisplayOrderInformation(editResponse.Order, true); bool saveEdit = ConsoleIO.GetYesNoAnswerFromUser("Would you like to submit and save the updated order information?"); if (saveEdit) { SaveOrderResponse saveResponse = orderManager.SaveOrder(editResponse.Order); if (saveResponse.Success) { ConsoleIO.YellowMessage($"\nUpdated Order: {editResponse.Order.OrderNumber} - {editResponse.Order.OrderDate:MM/dd/yyyy}"); } else { ConsoleIO.RedMessage($"An Error Occured: {saveResponse.Message}"); } } } else { ConsoleIO.RedMessage($"An Error Occured: {editResponse.Message}"); } } else { ConsoleIO.RedMessage(orderLookup.Message); } Console.WriteLine("\nPress any key to continue..."); Console.ReadKey(); }
public void Execute() { string workflow = "Edit"; OrderManager orderManager = OrderManagerFactory.Create(); StateTaxManager stateTaxManager = StateTaxManagerFactory.Create(); ProductManager productManager = ProductManagerFactory.Create(); Headers.DisplayHeader(workflow); //get date DateTime date = ConsoleIO.GetExistingOrderDate("Enter the date of the order you would like to edit (MM/DD/YYYY): "); Headers.DisplayHeader(workflow); //get order number int orderNumber = ConsoleIO.GetOrderNumberFromUser("Enter the order number: "); OrderGetSingleResponse orderResponse = orderManager.GetSingleOrder(date, orderNumber); if (orderResponse.Success) { Headers.DisplayHeader(workflow); ShowDetails.DisplayOrderDetails(orderResponse.Order); Console.WriteLine("Press any key to begin editing..."); Console.ReadKey(); } else { Console.WriteLine("An error occured:"); Console.WriteLine(orderResponse.Message); Console.WriteLine("Press any key to return to main menu..."); Console.ReadKey(); return; } Headers.DisplayHeader(workflow); //edit name string editName = ConsoleIO.GetCustomerName("Edit", orderResponse.Order.CustomerName); Headers.DisplayHeader(workflow); //edit state bool validInput = false; StateTax editStateTax = null; while (!validInput) { string editState = ConsoleIO.GetStateInputFromUser("Edit"); if (editState == "") { validInput = true; } else { StateTaxResponse stateTaxResponse = stateTaxManager.GetStateTax(editState); if (stateTaxResponse.Success == true) { editStateTax = stateTaxResponse.State; validInput = true; } } } Headers.DisplayHeader(workflow); //edit product type List <Product> products = productManager.GetProductList().Products; Product editProduct = ConsoleIO.DisplayProducts(products, "Edit"); Headers.DisplayHeader(workflow); //edit area decimal editArea = ConsoleIO.GetArea("Edit"); Headers.DisplayHeader(workflow); //display order changes Order editOrder = new Order(orderResponse.Order); if (editName != "") { editOrder.CustomerName = editName; } if (editStateTax != null) { editOrder.State = editStateTax.StateAbbreviation; editOrder.TaxRate = editStateTax.TaxRate; } if (editProduct != null) { editOrder.ProductType = editProduct.ProductType; editOrder.LaborCostPerSquareFoot = editProduct.LaborCostPerSquareFoot; editOrder.CostPerSquareFoot = editProduct.CostPerSquareFoot; } if (editArea != int.MaxValue) { editOrder.Area = editArea; } //send it! ShowDetails.DisplayOrderDetails(editOrder); if (ConsoleIO.GetYesOrNo("Submit changes to order?") == "Y") { OrderAddEditedResponse response = orderManager.AddEditedOrder(editOrder); if (!response.Success) { Console.WriteLine("There was an error adding the order:"); Console.WriteLine(response.Message); } else { Console.WriteLine("Order added! Press any key to return to main menu..."); Console.ReadKey(); } } else { Console.WriteLine("Edit order cancelled :( Press any key to continue..."); Console.ReadKey(); } }