Ejemplo n.º 1
0
        public void CanGetTax(string productType, bool expected)
        {
            ProductManager         productManager  = ProductManagerFactory.create();
            DisplayProductResponse productResponse = productManager.DisplayProductResponse(productType);

            Assert.AreEqual(productResponse.Success, expected);
        }
Ejemplo n.º 2
0
        public static string GetProduct(string prompt)
        {
            while (true)
            {
                ProductManager productManager     = ProductManagerFactory.Create();
                var            productLookup      = productManager.DisplayProducts();
                var            listOfProductNames = productLookup.Select(p => p.ProductType.ToUpper()).ToList();

                Console.Write(prompt);
                string format = "{0,-10} {1,20:c} {2,35:c}";
                Console.WriteLine(format, "\nProduct: ", "Cost per sq. ft.: ", "Labor cost per sq. ft.: ");

                for (int i = 0; i < productLookup.Count; i++)
                {
                    Console.WriteLine(format, $"{productLookup[i].ProductType}", $"${productLookup[i].CostPerSquareFoot}", $"${productLookup[i].LaborCostPerSqareFoot}");
                    Console.WriteLine();
                }

                string input = Console.ReadLine().ToUpper();
                if (!listOfProductNames.Contains(input))
                {
                    Console.WriteLine("You must enter a correct product name. Check your spelling.");
                    Console.WriteLine("Press any key to try again...");
                    Console.WriteLine();
                    Console.ReadKey();
                    Console.Clear();
                }
                else
                {
                    Console.Clear();
                    return(input.ToLower());
                }
            }
        }
Ejemplo n.º 3
0
        public static Order CreateOrder(DateTime orderDateInput, int orderNumberInput, string customerNameInput, string stateInput, string productTypeInput, decimal areaInput)
        {
            Conversions     convert        = new Conversions();
            TaxStateManager stateManager   = TaxStateManagerFactory.Create();
            ProductManager  productManager = ProductManagerFactory.Create();
            OrderManager    manager        = OrderManagerFactory.Create();
            Order           order          = new Order();

            order.OrderDate              = orderDateInput;
            order.OrderNumber            = orderNumberInput;
            order.CustomerName           = customerNameInput;
            order.State                  = stateInput;
            order.StateAbv               = stateManager.FindTaxState(stateInput).TaxState.StateCode;
            order.TaxRate                = stateManager.FindTaxState(stateInput).TaxState.TaxRate;
            order.ProductType            = productManager.FindProduct(productTypeInput).Product.ProductType;
            order.Area                   = areaInput;
            order.CostPerSqaureFoot      = productManager.FindProduct(productTypeInput).Product.CostPerSquareFoot;
            order.LaborCostPerSquareFoot = productManager.FindProduct(productTypeInput).Product.LaborCostPerSquareFoot;
            order.MaterialCost           = convert.MaterialCost(order, productManager.FindProduct(productTypeInput).Product);
            order.LaborCost              = convert.LaborCost(order, productManager.FindProduct(productTypeInput).Product);
            order.Tax   = convert.Tax(order, stateManager.FindTaxState(stateInput).TaxState);
            order.Total = convert.Total(order);

            return(order);
        }
Ejemplo n.º 4
0
        public void CanGetProductFromFile(string productType, bool expected)
        {
            ProductManager        productManager = ProductManagerFactory.Create();
            ProductLookupResponse response       = productManager.GetProduct(productType);

            Assert.AreEqual(expected, response.Success);
        }
Ejemplo n.º 5
0
        public void ChangeProduct(DisplaySingleOrderResponse response)
        {
            bool validProduct = false;

            while (!validProduct)
            {
                Console.Write(" Product Choice: ");
                string newProductType = (Console.ReadLine().ToUpper());

                if (!string.IsNullOrEmpty(newProductType))
                {
                    ProductManager productManager = ProductManagerFactory.Create();
                    Product        product        = productManager.ProductType(newProductType);

                    if (product != null)
                    {
                        validProduct = true;
                        response.OrderDetails.ProductType = newProductType;
                    }
                    else
                    {
                        Console.WriteLine(" Please enter a VALID product. ");
                    }
                }
                else
                {
                    validProduct = true;
                }
            }
        }
Ejemplo n.º 6
0
        private static string DisplayAndGetProducChoice()
        {
            string         productChoice  = "";
            ProductManager productManager = ProductManagerFactory.Create();

            foreach (var product in productManager.ListProducts())
            {
                Console.WriteLine("================================================================");
                Console.WriteLine("Product Type: " + product.ProductType);
                Console.WriteLine("Product Price Per SquareFoot: " + product.CostPerSquareFoot);
                Console.WriteLine("Labor Cost Per SquareFoot: " + product.LaborCostPerSquareFoot);
                Console.WriteLine("================================================================");
            }
            Console.WriteLine("Please Enter A Product Type: ");
            productChoice = Console.ReadLine();
            List <Product> products = new List <Product>();

            while (productManager.ListProducts().All(product => product.ProductType != productChoice))
            {
                Console.WriteLine("Product Type not supported; please, refference the list above.");
                Console.WriteLine("Product choice: ");
                productChoice = Console.ReadLine();
            }
            return(productChoice);
        }
Ejemplo n.º 7
0
        public void OrderProductType(Order order)
        {
            bool validProduct = false;

            while (!validProduct)
            {
                Console.Write(" Product Choice: ");
                string newProductType = (Console.ReadLine());
                if (!string.IsNullOrEmpty(newProductType))
                {
                    ProductManager productManager = ProductManagerFactory.Create();
                    TextInfo       textInfo       = new CultureInfo("en-US", false).TextInfo;
                    newProductType = textInfo.ToTitleCase(newProductType);
                    var product = productManager.ProductType(newProductType);
                    if (product != null)
                    {
                        validProduct                 = true;
                        order.ProductType            = newProductType;
                        order.CostPerSquareFoot      = product.CostPerSquareFoot;
                        order.LaborCostPerSquareFoot = product.LaborCostPerSquareFoot;
                    }
                    else
                    {
                        Console.WriteLine(" Please enter a VALID product. ");
                    }
                }
                else
                {
                    validProduct = true;
                }
            }
        }
Ejemplo n.º 8
0
        public void CanEditOrder(DateTime orderDate, int orderNumber, string newCustomerName, string newState, string newProductType, decimal newArea, bool expected)
        {
            OrderManager orderManager = OrderManagerFactory.create(orderDate);

            TaxManager         taxManager  = TaxManagerFactory.create();
            DisplayTaxResponse taxResponse = taxManager.DisplayTaxResponse(newState);

            ProductManager         productManager  = ProductManagerFactory.create();
            DisplayProductResponse productResponse = productManager.DisplayProductResponse(newProductType);

            Orders order = new Orders()
            {
                Area = newArea,
                CostPerSquareFoot      = productResponse.Products.CostPerSquareFoot,
                CustomerName           = newCustomerName,
                LaborCostPerSquareFoot = productResponse.Products.LaborCostPerSquareFoot,
                OrderNumber            = orderNumber,
                ProductType            = productResponse.Products.ProductType,
                State   = taxResponse.Tax.StateAbbreviation,
                TaxRate = taxResponse.Tax.TaxRate,
            };

            EditOrderResponse orderResponse = orderManager.EditOrder(order);

            Assert.AreEqual(orderResponse.Success, expected);
        }
Ejemplo n.º 9
0
        public void CanLoadProductTestData()
        {
            ProductManager manager = ProductManagerFactory.Create();

            ProductListResponse response = manager.ProductList();

            Assert.IsNotNull(response.Products);
            Assert.IsTrue(response.Success);
        }
Ejemplo n.º 10
0
        public void CanChooseProductTest()
        {
            ProductManager manager = ProductManagerFactory.Create();

            ProductLookupResponse response = manager.ChooseProduct("Carpet");

            Assert.IsNotNull(response.Product.ProductType);
            Assert.IsTrue(response.Success);
            Assert.AreEqual("Carpet", response.Product.ProductType);
        }
Ejemplo n.º 11
0
        public void RetrieveProductListTest()
        {
            ProductManager manager = ProductManagerFactory.Create();

            ProductListResponse response = manager.ProductsAvailable();

            Assert.IsNotNull(response.Products);

            Product product = response.Products.Find(p => p.ProductType == "Tile");

            Assert.AreEqual(product.ProductType, "Tile");
        }
Ejemplo n.º 12
0
        public void RetrieveProductInformationTest()
        {
            ProductManager manager = ProductManagerFactory.Create();

            ProductInformationResponse response = manager.ProductInformation("Tile");

            Assert.IsNotNull(response.Product);

            Product product = response.Product;

            Assert.AreEqual(product.ProductType, "Tile");
        }
Ejemplo n.º 13
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();
        }
Ejemplo n.º 14
0
        public static string GetProduct()
        {
            bool   validProductType = false;
            string product          = "";

            ProductManager productmanager = ProductManagerFactory.Create();

            do
            {
                Console.WriteLine("Please select a product.");
                Console.Write("Product Type: ");
                string productInput    = Console.ReadLine().ToUpper();
                var    selectedProduct = productmanager.GetProductInfo(productInput);

                if (string.IsNullOrEmpty(productInput))
                {
                    validProductType = true;
                    Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                    ConsoleIO.DisplayMessage($"Product empty.");
                    Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                }
                else
                {
                    if (selectedProduct == null)
                    {
                        Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                        ConsoleIO.DisplayMessage($"Error handling request.  Unavailable product.");
                        Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                    }
                    else
                    {
                        if (productmanager.ProductExistsInFile(selectedProduct.ProductType))
                        {
                            product = productInput;
                            Console.WriteLine("*********************************************");
                            ConsoleIO.DisplayMessage($"You have selected {selectedProduct.ProductType}");
                            Console.WriteLine("*********************************************");
                            validProductType = true;
                        }
                        else
                        {
                            Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                            ConsoleIO.DisplayMessage($"Error handling request.  Invalid input.");
                            Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                        }
                    }
                }
            } while (validProductType == false);
            return(product);
        }
Ejemplo n.º 15
0
        public static decimal GetCostLaborPerSquareFoot(string productType)
        {
            ProductManager productRepository = ProductManagerFactory.Create();
            decimal        costLabor         = 0;

            foreach (var product in productRepository.ListProducts())
            {
                if (product.ProductType == productType)
                {
                    costLabor = product.LaborCostPerSquareFoot;
                }
            }
            return(costLabor);
        }
Ejemplo n.º 16
0
        public static decimal GetCostMaterials(decimal area, string productType)
        {
            decimal materialCost = 0;

            ProductManager productRepository = ProductManagerFactory.Create();

            foreach (var product in productRepository.ListProducts())
            {
                if (product.ProductType == productType)
                {
                    materialCost = product.CostPerSquareFoot;
                }
            }
            return(materialCost * area);
        }
Ejemplo n.º 17
0
        public ActionResult Create(Product product)
        {
            if (ModelState.IsValid)
            {
                // 1-Force a exception to create a log using singleton instance
                //throw new Exception("Test log singleton");

                // 2-Cople code without factory pattern
                //if (product.CategoryId == 1)
                //{
                //	product.Bonus = 5;
                //	product.Tax = 2;
                //}
                //else if (product.CategoryId == 2)
                //{
                //	product.Bonus = 2;
                //	product.Tax = 5;
                //}
                //else if (product.CategoryId == 3)
                //{
                //	product.Bonus = 1;
                //	product.Tax = 7;
                //}

                // 3-Simple factory
                //ProductManagerFactory prodFactory = new ProductManagerFactory().CreateFactory;
                //IProductManager prodManager = prodFactory.GetProductManager(product.CategoryId);
                //product.Bonus = prodManager.GetBonus();
                //product.Tax = prodManager.GetTax();

                // 4-Factory Method
                BaseProductFactory prodFactory = new ProductManagerFactory().CreateFactory(product);
                prodFactory.ApplyBonusTax();


                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            var viewModel = new ProductViewModel
            {
                Categories = db.Categories.ToList()
            };

            return(View(viewModel));
        }
Ejemplo n.º 18
0
        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);
        }
Ejemplo n.º 19
0
        public static List <Product> CreateProductList()
        {
            ProductManager manager = ProductManagerFactory.Create();

            ProductListResponse plResponse = manager.GetProductList();

            if (plResponse.Success)
            {
                return(plResponse.Products);
            }
            else
            {
                Console.WriteLine("An error occured: ");
                Console.WriteLine(plResponse.Message);
            }

            return(plResponse.Products);
        }
Ejemplo n.º 20
0
        public static void RequestingProduct(Order order, bool newOrder)
        {
            //Show a list of available products and pricing information to choose from. Again,
            //if a product is added to the file it should show up in the application without a code change.


            string originalProduct = order.ProductType;

            ProductListResponse productResponse = ProductManagerFactory.Create().ProductsAvailable();
            List <Product>      products        = productResponse.Products;

            int productNumber = -1;

            while (true)
            {
                Console.Clear();
                Console.WriteLine(!newOrder ? "Select Number to Replace Current Product Type\n" :
                                  "Select Number for Which Product Type\n");

                Output.DisplayIO.DisplayProductsList(products);

                Console.Write(!newOrder ? $"\nEnter Product Type #({originalProduct})" :
                              "\nProduct Type (#): ");
                string selectedNumber = Console.ReadLine();

                if (!newOrder ? selectedNumber == "" : false)
                {
                    order.ProductType = originalProduct;
                    break;
                }


                if (!int.TryParse(selectedNumber, out productNumber))
                {
                    continue;
                }

                if (0 <= productNumber && productNumber <= (products.Count - 1))
                {
                    order.ProductType = products[productNumber].ProductType;
                    break;
                }
            }
        }
Ejemplo n.º 21
0
        private void AskToEditProductType()
        {
            ProductManager   productManager = ProductManagerFactory.Create(); //calls product repo
            AddOrderResponse response       = new AddOrderResponse();

            _productsList = productManager.GetProductsToDisplay();
            Console.Clear();
            ConsoleIO.DisplayProductsAvailable(_productsList);
            ConsoleIO.DisplaySingleOrder(_originalOrder);

            while (true)
            {
                Console.Write("Enter new product or just press enter to continue: ");
                string productType = Console.ReadLine();

                if (productType == "")
                {
                    _productType = productManager.GetProductInfo(_originalOrder.ProductType);
                    break;
                }
                else
                {
                    response = productManager.CheckProduct(productType);
                    if (response.Success == false)
                    {
                        Console.WriteLine("An error occurred with the product entered.  Contact IT.");
                        continue;
                    }
                    else
                    {
                        _productType = productManager.GetProductInfo(productType);
                        break;
                    }
                }
            }
        }
        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();
        }
Ejemplo n.º 23
0
        public void Execute()
        {
            OrderManager    manager        = OrderManagerFactory.Create();
            TaxStateManager stateManager   = TaxStateManagerFactory.Create();
            ProductManager  productManager = ProductManagerFactory.Create();
            InputRules      inputManager   = new InputRules();
            Order           order          = new Order();

            DateTime orderDate = DateTime.MinValue;

            Console.Clear();
            Console.WriteLine("Add an Order");
            Console.WriteLine("--------------------");


            //GET ORDER DATE
            OrderLookupResponse response     = new OrderLookupResponse();
            DateCheckResponse   dateResponse = new DateCheckResponse();

            dateResponse.Success = false;
            int orderNumber = 1;

            while (!dateResponse.Success)
            {
                Console.WriteLine("Please enter the Order Date you would like to add:");

                while (!DateTime.TryParse(Console.ReadLine(), out orderDate))
                {
                    Console.WriteLine("That is not a valid format, please try again");
                }
                dateResponse = inputManager.DateCheck(orderDate);
                Console.WriteLine(dateResponse.Message);
            }

            response = manager.AllOrderLookup(orderDate);

            if (response.Success)
            {
                foreach (Order entry in response.Orders)
                {
                    ConsoleIO.DisplayOrder(entry);
                }
                Console.WriteLine();
                Console.WriteLine("Here is the current status of this Order Date");
                if (response.Orders != null)
                {
                    orderNumber = response.Orders.LastOrDefault().OrderNumber + 1;
                }
            }


            //GET CUSTOMER NAME
            string            nameInput    = null;
            NameCheckResponse nameResponse = new NameCheckResponse();

            nameResponse.Success = false;

            while (!nameResponse.Success)
            {
                Console.Write("Enter the Customer's Name:  ");
                nameInput    = Console.ReadLine().Replace(',', '|').Trim();
                nameResponse = inputManager.NameCheck(nameInput);
                Console.WriteLine(nameResponse.Message);
            }
            Console.Clear();


            //GET STATE
            string stateInput = null;

            Console.WriteLine("These are the states in our system, please enter which state.");
            foreach (TaxState state in stateManager.GetTaxStates())
            {
                Console.WriteLine(state.StateName + ", " + state.StateCode);
            }

            TaxStateLookupResponse  stateResponse      = new TaxStateLookupResponse();
            StateInputCheckResponse stateInputResponse = new StateInputCheckResponse();

            stateResponse.Success      = false;
            stateInputResponse.Success = false;

            while (!stateResponse.Success)
            {
                while (!stateInputResponse.Success)
                {
                    Console.Write("Enter the State:  ");
                    stateInput         = Console.ReadLine();
                    stateInputResponse = inputManager.StateCheck(stateInput);
                    Console.WriteLine(stateInputResponse.Message);
                }

                stateResponse = stateManager.FindTaxState(stateInput);
                if (!stateResponse.Success)
                {
                    Console.WriteLine(stateResponse.Message);
                    Console.Write("Enter the State:  ");
                    stateInput = Console.ReadLine();
                }
            }
            Console.Clear();


            //GET PRODUCT MATERIAL
            string productInput = null;

            Console.WriteLine("These are the materials availbale to choose from:");
            foreach (Product product in productManager.GetProducts())
            {
                Console.WriteLine(string.Format("{0},  Labor Cost: {1},  Material Cost: {2}",
                                                product.ProductType,
                                                product.LaborCostPerSquareFoot,
                                                product.CostPerSquareFoot));
            }
            ProductLookupResposnse    productResponse      = new ProductLookupResposnse();
            ProductInputCheckResponse productInputResponse = new ProductInputCheckResponse();

            productResponse.Success      = false;
            productInputResponse.Success = false;

            while (!productResponse.Success)
            {
                while (!productInputResponse.Success)
                {
                    Console.Write("Enter the Type of materials:  ");
                    productInput         = Console.ReadLine();
                    productInputResponse = inputManager.ProductCheck(productInput);
                    Console.WriteLine(productInputResponse.Message);
                }

                productResponse = productManager.FindProduct(productInput);
                if (!productResponse.Success)
                {
                    Console.WriteLine(productResponse.Message);
                    Console.Write("Enter the Type of materials:  ");
                    productInput = Console.ReadLine();
                }
            }
            Console.Clear();


            //GET AREA
            decimal           areaInput    = 0;
            AreaCheckResponse areaResponse = new AreaCheckResponse();

            areaResponse.Success = false;
            while (!areaResponse.Success)
            {
                Console.Write("Enter the square footage of the Area:  ");
                while (!decimal.TryParse(Console.ReadLine(), out areaInput))
                {
                    Console.WriteLine("That is not a valid input.");
                }
                areaResponse = inputManager.AreaCheck(areaInput);
                Console.WriteLine(areaResponse.Message);
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();


            order = OrderCreation.CreateOrder(orderDate, orderNumber, nameInput, stateInput, productInput, areaInput);
            Console.Clear();
            ConsoleIO.DisplayOrder(order);
            Console.WriteLine();
            string answer = null;

            while (answer == null)
            {
                Console.WriteLine("Do you want to save this order? (Y/N)");
                answer = Console.ReadLine().ToUpper();
                switch (answer)
                {
                case "Y":
                    manager.CreateOrder(order);
                    Console.WriteLine("Order Saved");
                    break;

                case "N":
                    Console.WriteLine("Order Not Saved");
                    break;

                default:
                    Console.WriteLine("That is not a valid input, try again");
                    answer = null;
                    break;
                }
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
            return;
        }
        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();
        }
Ejemplo n.º 25
0
        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);
                }
            }
        }
Ejemplo n.º 26
0
        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();
            }
        }
        public void Execute()
        {
            ConsoleIO.ShowChoice("1.   Add Order");
            DateTime orderDate    = ConsoleIO.inputDate("Enter order date (MMddyyyy): ");
            string   customerName = ConsoleIO.inputName("Enter customer name: ", false);

            DisplayTaxResponse taxResponse;

            while (true)
            {
                string     state      = ConsoleIO.inputString("Enter state: ");
                TaxManager taxManager = TaxManagerFactory.create();
                taxResponse = taxManager.DisplayTaxResponse(state);
                if (!taxResponse.Success)
                {
                    Console.WriteLine("An error occurred: ");
                    Console.WriteLine(taxResponse.Message);
                }
                else
                {
                    break;
                }
            }

            DisplayProductResponse productResponse;

            while (true)
            {
                string         productType    = ConsoleIO.inputString("Enter product type: ");
                ProductManager productManager = ProductManagerFactory.create();
                productResponse = productManager.DisplayProductResponse(productType);
                if (!productResponse.Success)
                {
                    Console.WriteLine("An error occurred: ");
                    Console.WriteLine(productResponse.Message);
                }
                else
                {
                    break;
                }
            }

            decimal      area         = ConsoleIO.inputInt("Enter area: ", false);
            OrderManager orderManager = OrderManagerFactory.create(orderDate);
            Orders       order        = new Orders()
            {
                Area = area,
                CostPerSquareFoot      = productResponse.Products.CostPerSquareFoot,
                CustomerName           = customerName,
                LaborCostPerSquareFoot = productResponse.Products.LaborCostPerSquareFoot,
                OrderNumber            = orderManager.GenerateOrderNumber(),
                ProductType            = productResponse.Products.ProductType,
                State   = taxResponse.Tax.StateAbbreviation,
                TaxRate = taxResponse.Tax.TaxRate,
            };

            ConsoleIO.ShowSummary();
            ConsoleIO.DisplayOrderDetail(order);
            string result;

            while (true)
            {
                Console.Write("Do you want to place the order?(Y/N): ");
                result = Console.ReadLine();
                if (result.ToUpper() == "Y" || result.ToUpper() == "N")
                {
                    break;
                }
                else
                {
                    Console.Write("Invalid input.");
                }
            }

            if (result.ToUpper() == "N")
            {
                return;
            }


            AddOrderResponse orderResponse = orderManager.AddOrder(order);

            if (orderResponse.Success)
            {
                Console.WriteLine("order saved successfully.");
            }
            else
            {
                Console.WriteLine("An error occurred: ");
                Console.WriteLine(orderResponse.Message);
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Ejemplo n.º 28
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);
            }
        }
        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()
        {
            ConsoleIO.ShowChoice("2.   Edit Order");

            DateTime     orderDate;
            OrderManager orderManager;

            while (true)
            {
                orderDate    = ConsoleIO.inputDate("Enter order date (MMddyyyy): ");
                orderManager = OrderManagerFactory.create(orderDate);
                if (!orderManager.IfFileExist())
                {
                    Console.WriteLine("No order in this date!");
                    continue;
                }
                else
                {
                    break;
                }
            }


            Orders order;

            while (true)
            {
                int orderNumber = ConsoleIO.inputInt("Enter order number: ", false);
                order = orderManager.GetOrder(orderNumber);
                if (order is null)
                {
                    continue;
                }
                break;
            }

            string customerName = ConsoleIO.inputName($"Enter customer name({order.CustomerName}): ", true);

            if ((customerName + "").Trim() == "")
            {
                customerName = order.CustomerName;
            }

            DisplayTaxResponse taxResponse;

            while (true)
            {
                Console.Write($"Enter state({order.State}): ");
                string state = Console.ReadLine();

                if ((state + "").Trim() == "")
                {
                    state = order.State;
                }

                TaxManager taxManager = TaxManagerFactory.create();
                taxResponse = taxManager.DisplayTaxResponse(state.ToUpper());
                if (!taxResponse.Success)
                {
                    Console.WriteLine("An error occurred: ");
                    Console.WriteLine(taxResponse.Message);
                }
                else
                {
                    break;
                }
            }

            DisplayProductResponse productResponse;

            while (true)
            {
                Console.Write($"Enter product type({order.ProductType}): ");
                string productType = Console.ReadLine();
                if ((productType + "").Trim() == "")
                {
                    productType = order.ProductType;
                }

                ProductManager productManager = ProductManagerFactory.create();
                productResponse = productManager.DisplayProductResponse(productType);
                if (!productResponse.Success)
                {
                    Console.WriteLine("An error occurred: ");
                    Console.WriteLine(productResponse.Message);
                }
                else
                {
                    break;
                }
            }

            decimal area = ConsoleIO.inputInt($"Enter product type({order.Area}): ", true);

            if (area == -1)
            {
                area = order.Area;
            }

            order = new Orders()
            {
                Area = area,
                CostPerSquareFoot      = productResponse.Products.CostPerSquareFoot,
                CustomerName           = customerName,
                LaborCostPerSquareFoot = productResponse.Products.LaborCostPerSquareFoot,
                OrderNumber            = order.OrderNumber,
                ProductType            = productResponse.Products.ProductType,
                State   = taxResponse.Tax.StateAbbreviation,
                TaxRate = taxResponse.Tax.TaxRate,
            };

            ConsoleIO.ShowSummary();
            ConsoleIO.DisplayOrderDetail(order);
            string result;

            while (true)
            {
                Console.Write("Do you want to save the order?(Y/N): ");
                result = Console.ReadLine();
                if (result.ToUpper() == "Y" || result.ToUpper() == "N")
                {
                    break;
                }
                else
                {
                    Console.Write("Invalid input.");
                }
            }

            if (result.ToUpper() == "N")
            {
                return;
            }

            EditOrderResponse orderResponse = orderManager.EditOrder(order);

            if (orderResponse.Success)
            {
                Console.WriteLine("Order edited successfully.");
            }
            else
            {
                Console.WriteLine("An error occurred: ");
                Console.WriteLine(orderResponse.Message);
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }