Exemple #1
0
        public void ChangeState(DisplaySingleOrderResponse response)
        {
            bool validState = false;

            while (!validState)
            {
                Console.Write(" Enter State (with abbreviation or full name): ");
                string newState = (Console.ReadLine().ToUpper());

                if (!string.IsNullOrEmpty(newState))
                {
                    TaxManager taxManager = TaxManagerFactory.Create();
                    Tax        tax        = taxManager.TaxByState(newState);

                    if (tax != null)
                    {
                        validState = true;
                        response.OrderDetails.State = newState;
                    }
                    else
                    {
                        Console.WriteLine(" Please enter a VALID state. ");
                    }
                }
                else
                {
                    validState = true;
                }
            }
        }
Exemple #2
0
        public void OrderState(Order order)
        {
            bool validState = false;

            while (!validState)
            {
                Console.Write(" Enter State: ");
                string newState = (Console.ReadLine());
                if (!string.IsNullOrEmpty(newState))
                {
                    newState = newState.ToUpper();
                    TaxManager taxManager = TaxManagerFactory.Create();
                    Tax        tax        = taxManager.TaxByState(newState);
                    if (tax != null)
                    {
                        validState    = true;
                        order.State   = newState;
                        order.TaxRate = tax.TaxRate;
                    }
                    else
                    {
                        Console.WriteLine(" Please enter a VALID state. ");
                    }
                }
                else
                {
                    validState = true;
                }
            }
        }
Exemple #3
0
        public static string GetState(string prompt, string state)
        {
            while (true)
            {
                TaxManager taxManager     = TaxManagerFactory.Create();
                var        taxLookup      = taxManager.DisplayTaxes();
                var        listOfStateAbb = taxLookup.Select(p => p.StateAbbreviation.ToUpper()).ToList();

                Console.WriteLine(prompt);
                string input = Console.ReadLine().ToUpper();
                if (string.IsNullOrEmpty(input) || input == state)
                {
                    Console.Clear();
                    return(state);
                }
                if (!listOfStateAbb.Contains(input) || input.Length != 2)
                {
                    Console.WriteLine("We're sorry. We do not sell products in your region. Check your input.");
                    Console.WriteLine("Press any key to try again...");
                    Console.WriteLine();
                    Console.ReadKey();
                    Console.Clear();
                }
                else
                {
                    Console.Clear();
                    return(input);
                }
            }
        }
Exemple #4
0
        public void CanRestrieveTaxInformationTest()
        {
            TaxManager        manager  = TaxManagerFactory.Create();
            TaxLookUpResponse response = new TaxLookUpResponse();

            response = manager.TaxLookUp("OH");

            Assert.IsTrue(response.Success);
            Assert.AreEqual("OH", response.TaxInformation.StateAbbreviation);
        }
        public static string GetState()
        {
            //Get order state, do not let user pass while the stateinput is invalid
            bool       stateInputValid = false;
            string     state           = "";
            TaxManager taxmanager      = TaxManagerFactory.Create();

            do
            {
                Console.Clear();
                Console.WriteLine("*********************************");
                Console.WriteLine("Add an Order");
                Console.WriteLine("*********************************");
                Console.WriteLine("Please select the state the work is to be done in.");
                Console.WriteLine("Note that a state not on the list is ineligible for service.");

                var allStatesAvailable = taxmanager.GetAllStates();

                ConsoleIO.DisplayStates(allStatesAvailable);

                string customerStateInput = Console.ReadLine().ToUpper();

                if (string.IsNullOrEmpty(customerStateInput) == true)
                {
                    stateInputValid = true;
                    ConsoleIO.DisplayMessage("Empty input.");
                }
                else
                {
                    var selectedState = taxmanager.GetStateTaxInfo(customerStateInput);

                    if (selectedState == null)
                    {
                        ConsoleIO.DisplayMessage($"{customerStateInput} is not a state we are authorized to work in.");
                    }
                    else
                    {
                        if (taxmanager.StateExistsInFile(selectedState.StateName) == true)
                        {
                            state = customerStateInput;
                            ConsoleIO.DisplayMessage($"Work will be done in {selectedState.StateName}.");
                            stateInputValid = true;
                        }
                        else
                        {
                            ConsoleIO.DisplayMessage($"{customerStateInput} is not a state we are authorized to work in.");
                        }
                    }
                }
            } while (stateInputValid == false);
            return(state);
        }
Exemple #6
0
        public void Execute()
        {
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Green;
            Order          newOrder       = new Order();
            OrderManager   orderManager   = OrderManagerFactory.Create();
            TaxManager     taxManager     = TaxManagerFactory.Create();
            ProductManager productManager = ProductManagerFactory.Create();

            Console.WriteLine("Add Order");
            SeperatorBar();

            //Query User Info
            newOrder.Date         = QueryDate();
            newOrder.CustomerName = QueryCustomerName();
            newOrder.State        = QueryState();
            newOrder.ProductType  = QueryProductType();
            newOrder.Area         = QueryArea();

            //Calculations
            newOrder.TaxRate                = taxManager.GetStateTax(newOrder.State).TaxRate;
            newOrder.CostPerSquareFoot      = productManager.GetProductType(newOrder.ProductType).CostPerSquareFoot;
            newOrder.LaborCostPerSquareFoot = productManager.GetProductType(newOrder.ProductType).LaborCostPerSquareFoot;
            newOrder._calculateTotal();
            DisplayOrder(newOrder);

            if (YorN($"Are you sure you want to add your order?") == "Y")
            {
                AddOrderResponse response = orderManager.AddOrder(newOrder);
                if (response.Success)
                {
                    DisplayOrder(response.Order);
                    Console.WriteLine("Your order has been added to our files!");
                    Console.WriteLine(response.Message);
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("An error occured, your order was not saved");
                    Console.WriteLine(response.Message);
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Your order was not saved");
            }
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Exemple #7
0
        public static decimal GetTaxRate(string state)
        {
            decimal    taxRate    = 0;
            TaxManager taxManager = TaxManagerFactory.Create();

            foreach (var tax in taxManager.LookupTax(state))
            {
                if (state == tax.StateAbbreviation)
                {
                    taxRate = tax.TaxRate;
                }
            }
            return(taxRate);
        }
Exemple #8
0
        public static bool StateValidation(string input)
        {
            bool result = false;

            TaxLookUpResponse taxResponse = TaxManagerFactory.Create().TaxLookUp(input);

            if (taxResponse.Success)
            {
                result = true;
            }


            return(result);
        }
        public static void Field(Order order)

        {
            TaxLookUpResponse          taxResponse     = TaxManagerFactory.Create().TaxLookUp(order.State);
            ProductInformationResponse productResponse = ProductManagerFactory.Create().ProductInformation(order.ProductType);


            order.TaxRate            = Math.Round(taxResponse.TaxInformation.TaxRate, 2);
            order.CostPerSquareFoot  = Math.Round(productResponse.Product.CostPerSquareFoot, 2);
            order.LaborCostPerSquare = Math.Round(productResponse.Product.LaborCostPerSquareFoot, 2);


            order.MaterialCost = Math.Round(order.Area * order.CostPerSquareFoot, 2);
            order.LaborCost    = Math.Round(order.Area * order.LaborCostPerSquare, 2);

            order.Tax   = Math.Round(((order.MaterialCost + order.LaborCost) * (order.TaxRate / 100)), 2);
            order.Total = Math.Round((order.MaterialCost + order.LaborCost + order.Tax), 2);
        }
Exemple #10
0
        public static string MakeValidState()
        {
            TaxManager taxRepository  = TaxManagerFactory.Create();
            string     userInputState = Console.ReadLine().ToUpper();

            if (!taxRepository.LookupTax(userInputState).Any(state => state.StateAbbreviation == userInputState))
            {
                Console.WriteLine("State is not supported");
                Console.WriteLine("press any key to exit");
                Console.ReadKey();
                return(null);
            }

            else
            {
                return(userInputState);
            }
        }
        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);
                }
            }
        }
 public void StateCheck(string state, bool expectedResult)
 {
     TaxManager taxManager = TaxManagerFactory.Create();
     Tax        tax        = taxManager.TaxByState(state);
 }
        public void Execute()
        {
            OrderManager   orderManager   = OrderManagerFactory.Create();
            ProductManager productManager = ProductManagerFactory.Create();
            TaxManager     taxManager     = TaxManagerFactory.Create();

            Console.Clear();
            Console.WriteLine("Edit an order");
            Console.WriteLine(ConsoleIO.LineBar);
            Console.WriteLine();
            Console.WriteLine("Press any key to edit an order.");
            Console.ReadKey();
            Console.Clear();

            Order editOrder = new Order();

            editOrder.OrderDate   = EditOrderCheck.GetDate("Enter the order date (MMDDYYYY): ");
            editOrder.OrderNumber = int.Parse(EditOrderCheck.GetOrderNumber("Enter the order number you would like to edit: "));

            EditOrderResponse response = orderManager.EditOrder(editOrder.OrderDate, editOrder.OrderNumber);

            Console.Clear();

            if (response.Success && response.Order != null)
            {
                editOrder.CustomerName = EditOrderCheck.GetName($"Enter customer name ({response.Order.CustomerName}): ", response.Order.CustomerName);
                editOrder.State        = EditOrderCheck.GetState($"Enter your state location ({response.Order.State}): ", response.Order.State);
                editOrder.ProductType  = EditOrderCheck.GetProduct($"Enter product you would like to order ({response.Order.ProductType}): ", response.Order.ProductType);
                editOrder.Area         = decimal.Parse(EditOrderCheck.GetArea($"Enter area amount you would like to order (minimum of 100sq ft) ({response.Order.Area}sq ft): ", response.Order.Area));

                var productLookup = productManager.ReturnProduct(editOrder.ProductType);
                editOrder.CostPerSquareFoot     = productLookup.CostPerSquareFoot;
                editOrder.LaborCostPerSqareFoot = productLookup.LaborCostPerSqareFoot;

                var taxesLookup = taxManager.LoadTax(editOrder.State);
                editOrder.TaxRate = taxesLookup.TaxRate;

                editOrder.MaterialCost = editOrder.MaterialCostCalc(editOrder.Area, editOrder.CostPerSquareFoot);
                editOrder.LaborCost    = editOrder.LaborCostCalc(editOrder.Area, editOrder.LaborCostPerSqareFoot);
                editOrder.Tax          = editOrder.TaxCalc(editOrder.MaterialCost, editOrder.LaborCost, editOrder.TaxRate);
                editOrder.Total        = editOrder.TotalCalc(editOrder.MaterialCost, editOrder.LaborCost, editOrder.Tax);
            }

            if (response.Order == null || response.Orders.Count() == 0)
            {
                Console.WriteLine("An error occurred: ");
                Console.WriteLine($"Order date {editOrder.OrderDate} and / or Order # {editOrder.OrderNumber} does not exist.");
                Console.WriteLine();
                Console.WriteLine("Press any key to return to the main menu...");
                Console.ReadKey();
                Console.Clear();
                return;
            }

            Console.Clear();
            ConsoleIO.DisplayOrderDetails(editOrder);
            bool keepLooping = true;

            do
            {
                Console.WriteLine();
                Console.WriteLine("Would you like to save your edited order? Y for Yes or N for No: ");
                string input = Console.ReadLine();
                if (input.ToUpper() == "Y" || input.ToUpper() == "Yes")
                {
                    orderManager.ExportEditOrder(response.Orders, editOrder, editOrder.OrderDate, editOrder.OrderNumber);

                    Console.WriteLine();
                    Console.WriteLine("Your order has been edited.");
                    keepLooping = false;
                }
                else if (input.ToUpper() == "N" || input.ToUpper() == "No")
                {
                    Console.WriteLine();
                    Console.WriteLine("No edits were made to your order.");
                    keepLooping = false;
                }
                else
                {
                    Console.WriteLine();
                    Console.WriteLine("You pressed an incorrect key. Press enter to try again...");
                    Console.ReadKey();
                    keepLooping = true;
                }
            } while (keepLooping == true);

            Console.WriteLine();
            Console.WriteLine("Press any key to return to the main menu...");
            Console.ReadKey();
        }
Exemple #14
0
        public void Execute()
        {
            Console.ForegroundColor = ConsoleColor.Green;
            OrderManager orderManager = OrderManagerFactory.Create();
            TaxManager taxManager = TaxManagerFactory.Create();
            ProductManager productManager = ProductManagerFactory.Create();


            Order newOrder = new Order();

            Console.Clear();
            Console.WriteLine("Edit Order");
            SeperatorBar();

            //Query Access To Order To Edit
            int orderNumber = QueryOrderNumber();
            DateTime orderDate = QueryDate();
            Order oldOrder = orderManager.DisplayOrder(orderNumber, orderDate).Order;
            DisplayOrder(oldOrder);

            //define edit in models
            if (YorN($"Are you sure you want to edit your order?") == "Y")
            {
                try
                {
                    OrderResponse oldOrderResponse = orderManager.DisplayOrder(orderNumber, orderDate);

                    if (oldOrderResponse.Success)
                    {
                        bool flag = true;
                        while (flag)
                        {
                            Console.WriteLine("Edit the Order Customer Name or press enter to keep the Old Order's Customer Name the same.");
                            if (Console.ReadLine() != "")
                            {
                                newOrder.CustomerName = QueryCustomerName();
                            }
                            else
                            {
                                newOrder.CustomerName = oldOrder.CustomerName;
                            }
                            Console.WriteLine("Edit the Order State or press enter to keep the Old Order's State the same.");
                            if (Console.ReadLine() != "")
                            {
                                newOrder.State = QueryState();
                            }
                            else
                            {
                                newOrder.State = oldOrder.State;
                            }
                            Console.WriteLine("Edit the Order Product Type or press enter to keep the Old Order's Product Type the same.");
                            if (Console.ReadLine() != "")
                            {
                                newOrder.ProductType = QueryProductType();
                            }
                            else
                            {
                                newOrder.ProductType = oldOrder.ProductType;
                            }
                            Console.WriteLine("Edit the Order Area or press enter to keep the Old Order's Area the same.");
                            if (Console.ReadLine() != "")
                            {
                                newOrder.Area = QueryArea();
                            }
                            else
                            {
                                newOrder.Area = oldOrder.Area;
                            }
                            newOrder.TaxRate = taxManager.GetStateTax(newOrder.State).TaxRate;
                            newOrder.CostPerSquareFoot = productManager.GetProductType(newOrder.ProductType).CostPerSquareFoot;
                            newOrder.LaborCostPerSquareFoot = productManager.GetProductType(newOrder.ProductType).LaborCostPerSquareFoot;
                            newOrder._calculateTotal();

                            flag = false;
                        }

                        EditOrderResponse response = orderManager.EditOrder(oldOrder, newOrder, orderDate, orderNumber);
                        if (response.Success)
                        {
                            Console.ForegroundColor = ConsoleColor.Green;
                            DisplayOrder(response.NewOrder);
                            Console.WriteLine("Your order has been successfully edited.");
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine("An error occured, youe old order should still be in the database");
                            Console.WriteLine(response.Message);
                        }
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("Press any key to continue...");
                        Console.ReadKey();
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Your order was not saved");
                    }
                }
                catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("There was an issue with your input, redirecting you back to the menu");
                    Console.WriteLine("Press any key to continue...");
                    Console.ReadKey();
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("An error occured");
            }
        }
        public void Execute()
        {
            OrderManager   orderManager   = OrderManagerFactory.Create();
            ProductManager productManager = ProductManagerFactory.Create();
            TaxManager     taxManager     = TaxManagerFactory.Create();

            Console.Clear();
            Console.WriteLine("Place an order");
            Console.WriteLine(ConsoleIO.LineBar);
            Console.WriteLine();
            Console.WriteLine("Press any key to start your order.");
            Console.ReadKey();
            Console.Clear();

            Order newOrder = new Order();

            newOrder.OrderDate    = AddOrderCheck.GetDate("Enter a future order date (MMDDYYYY): ");
            newOrder.CustomerName = AddOrderCheck.GetName("Enter customer name: ");
            newOrder.State        = AddOrderCheck.GetState("Enter your State location (ex. OH for Ohio): ");
            newOrder.ProductType  = AddOrderCheck.GetProduct("Enter product you would like to order: ");
            newOrder.Area         = decimal.Parse(AddOrderCheck.GetArea("Enter area amount you would like to order (minimum of 100sq ft): "));

            var productLookup = productManager.ReturnProduct(newOrder.ProductType);

            newOrder.CostPerSquareFoot     = productLookup.CostPerSquareFoot;
            newOrder.LaborCostPerSqareFoot = productLookup.LaborCostPerSqareFoot;

            var taxesLookup = taxManager.LoadTax(newOrder.State);

            newOrder.TaxRate = taxesLookup.TaxRate;

            newOrder.MaterialCost = newOrder.MaterialCostCalc(newOrder.Area, newOrder.CostPerSquareFoot);
            newOrder.LaborCost    = newOrder.LaborCostCalc(newOrder.Area, newOrder.LaborCostPerSqareFoot);
            newOrder.Tax          = newOrder.TaxCalc(newOrder.MaterialCost, newOrder.LaborCost, newOrder.TaxRate);
            newOrder.Total        = newOrder.TotalCalc(newOrder.MaterialCost, newOrder.LaborCost, newOrder.Tax);

            AddOrderResponse response = orderManager.AddOrder(newOrder, newOrder.OrderDate);

            Console.Clear();

            if (response.Success)
            {
                ConsoleIO.DisplayOrderDetails(response.NewOrder);
                bool keepLooping = true;

                do
                {
                    Console.WriteLine();
                    Console.WriteLine("Would you like to save your new order? Y for Yes or N for No: ");
                    string input = Console.ReadLine();
                    if (input.ToUpper() == "Y" || input.ToUpper() == "Yes")
                    {
                        Console.WriteLine();
                        Console.WriteLine("Your order has been placed.");
                        keepLooping = false;
                    }
                    else if (input.ToUpper() == "N" || input.ToUpper() == "No")
                    {
                        orderManager.RemoveOrder(newOrder, newOrder.OrderDate, newOrder.OrderNumber);
                        Console.WriteLine();
                        Console.WriteLine("Your order has been cancelled.");
                        keepLooping = false;
                    }
                    else
                    {
                        Console.WriteLine();
                        Console.WriteLine("You pressed an incorrect key. Press enter to try again...");
                        Console.ReadKey();
                        keepLooping = true;
                    }
                } while (keepLooping == true);
            }
            else
            {
                Console.WriteLine();
                Console.WriteLine("An error occurred: ");
                Console.WriteLine(response.Message);
            }
            Console.WriteLine();
            Console.WriteLine("Press any key to return to the main menu...");
            Console.ReadKey();
        }
Exemple #16
0
        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);
            }
        }
Exemple #17
0
        internal static AddOrderResponse MakeValidOrder()
        {
            AddOrderResponse addOrderResponse = new AddOrderResponse();

            string orderdate = MakeValidOrderDate();

            Console.Write("enter customer name: ");
            string customername = Console.ReadLine();

            Console.WriteLine("Enter your state's abreviation.");
            Console.WriteLine("Chose from: ");
            TaxManager taxManager = TaxManagerFactory.Create();

            foreach (var someTax in taxManager.GetTaxs())
            {
                Console.WriteLine(someTax.StateAbbreviation);
            }
            ;
            string state = MakeValidState();

            if (state == null)
            {
                addOrderResponse.OrderToAdd = null;
                addOrderResponse.Success    = false;
                addOrderResponse.Message    = "Error: State Not Supported";
                return(addOrderResponse);
            }
            string  productType            = DisplayAndGetProducChoice();
            decimal area                   = GetValidArea();
            decimal costLaborPerSquareFoot = GetCostLaborPerSquareFoot(productType);
            decimal materialCost           = GetCostMaterials(area, productType);
            int     orderNumber            = GetOrderNumber(orderdate);
            decimal taxRate                = GetTaxRate(state);
            decimal tax               = (materialCost + (costLaborPerSquareFoot * area)) * (taxRate / 100);
            decimal laborCost         = costLaborPerSquareFoot * area;
            decimal total             = tax + materialCost + laborCost;
            decimal costPerSquareFoot = materialCost / area;

            Order order = new Order
            {
                OrderDate              = orderdate,
                CustomerName           = customername,
                State                  = state,
                ProductType            = productType,
                Area                   = area,
                LaborCostPerSquareFoot = costLaborPerSquareFoot,
                LaborCost              = laborCost,
                MaterialCost           = materialCost,
                CostPerSquareFoot      = costPerSquareFoot,
                OrderNumber            = orderNumber,
                TaxRate                = taxRate,
                Total                  = total,
                Tax = tax
            };

            addOrderResponse.OrderToAdd = order;
            addOrderResponse.Success    = true;
            addOrderResponse.Message    = "Success";

            return(addOrderResponse);
        }
        public void Exicute()
        {
            Console.Clear();
            OrderManager orderManager = OrderManagerFactory.Create();

            Console.WriteLine("Enter an Order Date: ");

            string userInputDate = orderManager.GetValidDate(Console.ReadLine());

            if (userInputDate != null)
            {
                Console.WriteLine("Enter an Order Number: ");
                string userInputOrderNumber = Console.ReadLine();
                int    orderNumber          = int.MinValue;
                while (!userInputOrderNumber.All(char.IsDigit))
                {
                    Console.WriteLine("ERROR: Enter Order number as an int:");
                    userInputOrderNumber = Console.ReadLine();
                }
                while (!int.TryParse(userInputOrderNumber, out orderNumber))
                {
                    Console.WriteLine("order number must be entered as an int");
                    Console.WriteLine("enter order number:");
                    userInputOrderNumber = Console.ReadLine();
                }
                string inputOrderNumber = orderManager.GetValidOrderNumber(userInputOrderNumber, userInputDate);
                if (inputOrderNumber == null)

                {
                    Console.WriteLine("Order Number Does not Exist for that date");
                    Console.Write("Press any Key to Continue");
                    Console.ReadKey();
                }
                else
                {
                    Order editedOrder          = new Order();
                    IEnumerable <Order> orders = orderManager.LookupOder(userInputDate).Orders.Where(order => order.OrderNumber.ToString() == userInputOrderNumber);//here
                    string  customerName       = "";
                    string  state        = "";
                    string  productType  = "";
                    string  areaAsString = "";
                    decimal area         = 0;
                    foreach (var order in orders)
                    {
                        Console.WriteLine("Enter Customer Name (" + order.CustomerName + "):");
                        customerName = Console.ReadLine();
                        if (customerName == "")
                        {
                            customerName = order.CustomerName;
                        }
                        Console.WriteLine("Enter State (" + order.State + "):");
                        state = Console.ReadLine();
                        if (state == "")
                        {
                            state = order.State;
                            Console.WriteLine("Enter Product Type (" + order.ProductType + "):");
                            productType = Console.ReadLine();
                            if (productType == "")
                            {
                                productType = order.ProductType;
                            }
                            else
                            {
                                ProductManager productManager = ProductManagerFactory.Create();
                                while (productManager.ListProducts().All(product => product.ProductType != productType))
                                {
                                    Console.WriteLine("invalid product type. product types are: ");
                                    foreach (var product in productManager.ListProducts())
                                    {
                                        Console.WriteLine(product.ProductType);
                                    }
                                    Console.WriteLine("Enter Product Type:");
                                    productType = Console.ReadLine();
                                }
                            }

                            Console.WriteLine("Enter Area (" + order.Area + "):");
                            areaAsString = Console.ReadLine();
                            if (areaAsString == "")
                            {
                                area = order.Area;
                            }
                            else
                            {
                                while (!decimal.TryParse(areaAsString, out area) || area < 100)
                                {
                                    Console.WriteLine("area must be a decimal > 100");
                                    areaAsString = Console.ReadLine();
                                }

                                area = decimal.Parse(areaAsString);
                            }

                            editedOrder = order;

                            editedOrder.MaterialCost           = SubLogic.GetCostMaterials(area, productType);
                            editedOrder.CostPerSquareFoot      = (SubLogic.GetCostMaterials(area, productType)) / area;
                            editedOrder.TaxRate                = SubLogic.GetTaxRate(state);
                            editedOrder.LaborCostPerSquareFoot = SubLogic.GetCostLaborPerSquareFoot(productType);
                            editedOrder.LaborCost              = SubLogic.GetCostLaborPerSquareFoot(productType) * area;
                            editedOrder.Area         = area;
                            editedOrder.CustomerName = customerName;
                            editedOrder.ProductType  = productType;
                            editedOrder.State        = state;
                            editedOrder.Tax          = (editedOrder.MaterialCost + editedOrder.LaborCost) * (editedOrder.TaxRate / 100);
                            editedOrder.Total        = (editedOrder.Tax + editedOrder.MaterialCost + editedOrder.LaborCost);

                            Console.WriteLine("Are you sure you would like to Edit This Order?");
                            Console.WriteLine("Enter Y to save changes: ");
                            if (Console.ReadLine() == "Y")
                            {
                                editedOrder.OrderDate = userInputDate;
                                bool wasEdited = orderManager.SaveEditedOrder(editedOrder);
                                Console.Clear();
                                Console.WriteLine("Changes have been Saved. press any key to continue");
                                Console.ReadKey();
                            }
                            else
                            {
                                Console.Clear();
                                Console.WriteLine("Changes were not Saved. press any key to continue");
                                Console.ReadKey();
                            }
                        }
                        else
                        {
                            TaxManager taxRepository = TaxManagerFactory.Create();
                            if (taxRepository.LookupTax(state).Any(tax => tax.StateAbbreviation == state))
                            {
                                Console.WriteLine("Enter Product Type (" + order.ProductType + "):");
                                productType = Console.ReadLine();
                                if (productType == "")
                                {
                                    productType = order.ProductType;
                                }
                                Console.WriteLine("Enter Area (" + order.Area + "):");
                                areaAsString = Console.ReadLine();
                                if (areaAsString == "")
                                {
                                    area = order.Area;
                                }
                                else
                                {
                                    area = decimal.Parse(areaAsString);
                                }

                                editedOrder = order;

                                editedOrder.MaterialCost           = SubLogic.GetCostMaterials(area, productType);
                                editedOrder.CostPerSquareFoot      = (SubLogic.GetCostMaterials(area, productType)) / area;
                                editedOrder.TaxRate                = SubLogic.GetTaxRate(state);
                                editedOrder.LaborCostPerSquareFoot = SubLogic.GetCostLaborPerSquareFoot(productType);
                                editedOrder.LaborCost              = SubLogic.GetCostLaborPerSquareFoot(productType) * area;
                                editedOrder.Area         = area;
                                editedOrder.CustomerName = customerName;
                                editedOrder.ProductType  = productType;
                                editedOrder.State        = state;
                                editedOrder.Tax          = (editedOrder.MaterialCost + editedOrder.LaborCost) * (editedOrder.TaxRate / 100);
                                editedOrder.Total        = (editedOrder.Tax + editedOrder.MaterialCost + editedOrder.LaborCost);

                                Console.WriteLine("Are you sure you would like to Edit This Order?");
                                Console.WriteLine("Enter Y to save changes: ");
                                if (Console.ReadLine() == "Y")
                                {
                                    orderManager.SaveEditedOrder(editedOrder);
                                    Console.Clear();
                                    Console.WriteLine("Changes have been Saved. press any key to continue");
                                    Console.ReadKey();
                                }
                                else
                                {
                                    Console.Clear();
                                    Console.WriteLine("Changes were not Saved. press any key to continue");
                                    Console.ReadKey();
                                }
                            }
                            else
                            {
                                Console.WriteLine("State is not supported");
                                Console.WriteLine("press any key to exit");
                                Console.ReadKey();
                            }
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("File for Date Does not Exist");
                Console.Write("Press any Key to Continue");
                Console.ReadKey();
            }
        }