Ejemplo n.º 1
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.º 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 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.º 4
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.º 5
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.º 6
0
        public void CanGetProductFromFile(string productType, bool expected)
        {
            ProductManager        productManager = ProductManagerFactory.Create();
            ProductLookupResponse response       = productManager.GetProduct(productType);

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

            ProductListResponse response = manager.ProductList();

            Assert.IsNotNull(response.Products);
            Assert.IsTrue(response.Success);
        }
Ejemplo n.º 8
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.º 9
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.º 10
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.º 11
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.º 12
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.º 13
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.º 14
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.º 15
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.º 16
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.º 17
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.º 18
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()
        {
            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.º 20
0
        public void Execute()
        {
            OrderManager   manager        = OrderManagerFactory.Create();
            StateManager   stateManager   = StateManagerFactory.Create();
            ProductManager productManager = ProductManagerFactory.Create();


            ConsoleIO.OrderHeader("Edit an Order:");
            Console.WriteLine("Please enter the date of the order you would like to edit.");

            var repo = manager.GetAllOrders(ConsoleIO.GetDateFromUser());

            if (repo.Success)
            {
                ConsoleIO.OrderHeader("Edit an Order:");
                ConsoleIO.DisplayAllOdersForDate(repo.Orders);
                Console.WriteLine(ConsoleIO.SeparatorBar);
                Console.WriteLine();

                int orderNumber = ConsoleIO.GetOrderNumberFromUser("Which order number would you like to edit?: ");
                var ordertoedit = manager.LookupOrder(ConsoleIO.OrderDate, orderNumber);
                if (ordertoedit.Success)
                {
                    ConsoleIO.OrderHeader("Edit an Order:");
                    Console.WriteLine("Type the information to edit in the following prompts.\n If you wish to keep the information in parenthesis simply press enter.");
                    string name = ConsoleIO.GetCustomerNameEdit(ordertoedit.Order.Name);
                    if (!string.IsNullOrEmpty(name))
                    {
                        ordertoedit.Order.Name = name;
                    }
                    var response = stateManager.ListAllStates();
                    if (response.Success)
                    {
                        ConsoleIO.OrderHeader("Edit an Order:Type the information to edit in the following prompts.\n If you wish to keep the information in parenthesis simply press enter.");
                        ConsoleIO.DisplayAllStates(response.StateList);
                        Console.WriteLine();
                        while (true)
                        {
                            string state = ConsoleIO.GetStateForEdit(ordertoedit.Order.State);
                            if (!string.IsNullOrEmpty(state))
                            {
                                var StateTax = stateManager.LookupState(state);
                                if (StateTax.Success)
                                {
                                    ordertoedit.Order.State   = StateTax.StateTax.State;
                                    ordertoedit.Order.TaxRate = StateTax.StateTax.TaxRate;
                                    break;
                                }
                                else
                                {
                                    Console.WriteLine(StateTax.Message);
                                    ConsoleIO.EnterKeyToContinue();
                                }
                            }
                            break;
                        }
                    }
                    ConsoleIO.OrderHeader("Edit an Order:Type the information to edit in the following prompts.\n If you wish to keep the information in parenthesis simply press enter.");
                    var productresponse = productManager.ProductList();
                    if (productresponse.Success)
                    {
                        ConsoleIO.DisplayAllProducts(productresponse.Products);
                        Console.WriteLine();

                        while (true)
                        {
                            string product = ConsoleIO.GetProductTypeForEdit(ordertoedit.Order.PrductType);
                            if (!string.IsNullOrEmpty(product))
                            {
                                var customerProduct = productManager.ChooseProduct(product);
                                if (customerProduct.Success)
                                {
                                    ordertoedit.Order.PrductType             = customerProduct.Product.ProductType;
                                    ordertoedit.Order.CostPerSqureFoot       = customerProduct.Product.CostPerSquareFoot;
                                    ordertoedit.Order.LaborCostPerSquareFoot =
                                        customerProduct.Product.LaborCostPerSquareFoot;
                                    break;
                                }

                                else
                                {
                                    Console.WriteLine(customerProduct.Message);
                                    ConsoleIO.EnterKeyToContinue();
                                }
                            }
                            break;
                        }

                        while (true)
                        {
                            decimal area;
                            ConsoleIO.OrderHeader("Edit an Order:Type the information to edit in the following prompts. \nIf you wish to keep the information in parenthesis simply press enter.");
                            Console.Write($"Enter the squarefootage for the floor ({ordertoedit.Order.Area}): ");
                            string input = Console.ReadLine();
                            if (string.IsNullOrEmpty(input))
                            {
                                break;
                            }
                            if (!decimal.TryParse(input, out area))
                            {
                                Console.WriteLine("You must enter valid number.");
                                Console.WriteLine("Press any key to continue...");
                                Console.ReadKey();
                            }
                            if (area < 100)
                            {
                                Console.WriteLine("The square foot area must be at least 100 square feet.");
                                ConsoleIO.EnterKeyToContinue();
                            }

                            else
                            {
                                ordertoedit.Order.Area = area;
                                break;
                            }
                        }
                        ConsoleIO.OrderHeader("Edit an Order:");
                        ConsoleIO.DisplayOrders(ordertoedit.Order);
                        string answer = ConsoleIO.GetYesNoAnswerFromUser("Would you like to update this order?: ");
                        if (answer == "Y")
                        {
                            var editResponse = manager.EditOrder(ordertoedit.Order, ConsoleIO.OrderDate);
                            if (editResponse.Success)
                            {
                                Console.WriteLine("The order was updated!");
                                ConsoleIO.EnterKeyToContinue();
                            }
                            else
                            {
                                Console.WriteLine(editResponse.Message);
                                ConsoleIO.EnterKeyToContinue();
                            }
                        }
                        else
                        {
                            Console.WriteLine("The edit was cancelled.");
                            ConsoleIO.EnterKeyToContinue();
                        }


                        ordertoedit.Order.MaterialCost = ordertoedit.Order.Area * ordertoedit.Order.CostPerSqureFoot;
                        ordertoedit.Order.LaborCost    = ordertoedit.Order.Area * ordertoedit.Order.LaborCostPerSquareFoot;
                        ordertoedit.Order.Tax          = (ordertoedit.Order.MaterialCost + ordertoedit.Order.LaborCost) *
                                                         (ordertoedit.Order.TaxRate / 100);
                        ordertoedit.Order.Total = ordertoedit.Order.MaterialCost + ordertoedit.Order.LaborCost +
                                                  ordertoedit.Order.Tax;

                        Console.Clear();
                        ConsoleIO.DisplayOrders(ordertoedit.Order);
                        Console.WriteLine(ConsoleIO.SeparatorBar);
                    }

                    else
                    {
                        Console.WriteLine(response.Message);
                        ConsoleIO.EnterKeyToContinue();
                    }
                }

                else
                {
                    Console.WriteLine(ordertoedit.Message);
                    ConsoleIO.EnterKeyToContinue();
                }
            }
            else
            {
                Console.WriteLine(repo.Message);
                ConsoleIO.EnterKeyToContinue();
            }
        }
        public void Execute()
        {
            Console.Clear();
            StateManager   stateManager   = StateManagerFactory.Create();
            ProductManager productManager = ProductManagerFactory.Create();
            OrderManager   orderManager   = OrderManagerFactory.Create();
            Orders         newOrder       = new Orders();


            ConsoleIO.OrderHeader("Add an Order");
            Console.WriteLine("Please enter a future date for the order.");
            newOrder.orderDate = ConsoleIO.GetFutureDateFromUser();
            var numberResponse = orderManager.GetOrderNumber(ConsoleIO.OrderDate);

            newOrder.OrderNumber = numberResponse.OrderNumber;
            newOrder.Name        = ConsoleIO.GetCustomerNameFromUserForAdd();
            Console.Clear();
            var response = stateManager.ListAllStates();

            if (response.Success)
            {
                ConsoleIO.OrderHeader("Add an Order");
                ConsoleIO.DisplayAllStates(response.StateList);
                while (true)
                {
                    string state    = ConsoleIO.GetStateFromUserForAdd();
                    var    StateTax = stateManager.LookupState(state);
                    if (StateTax.Success)
                    {
                        newOrder.State   = StateTax.StateTax.State;
                        newOrder.TaxRate = StateTax.StateTax.TaxRate;
                        break;
                    }
                    else
                    {
                        Console.WriteLine(StateTax.Message);
                        ConsoleIO.EnterKeyToContinue();
                    }
                }
                ConsoleIO.OrderHeader("Add an Order");
                var productresponse = productManager.ProductList();
                if (productresponse.Success)
                {
                    ConsoleIO.DisplayAllProducts(productresponse.Products);

                    while (true)
                    {
                        string product         = ConsoleIO.GetProductTypeFromUser();
                        var    customerProduct = productManager.ChooseProduct(product);
                        if (customerProduct.Success)
                        {
                            newOrder.PrductType             = customerProduct.Product.ProductType;
                            newOrder.CostPerSqureFoot       = customerProduct.Product.CostPerSquareFoot;
                            newOrder.LaborCostPerSquareFoot = customerProduct.Product.LaborCostPerSquareFoot;
                            break;
                        }

                        else
                        {
                            Console.WriteLine(customerProduct.Message);
                            ConsoleIO.EnterKeyToContinue();
                        }
                    }
                    ConsoleIO.OrderHeader("Add an Order");
                    Console.WriteLine(ConsoleIO.SeparatorBar);
                    newOrder.Area = ConsoleIO.GetAreaFromUser();



                    newOrder.MaterialCost = newOrder.Area * newOrder.CostPerSqureFoot;
                    newOrder.LaborCost    = newOrder.Area * newOrder.LaborCostPerSquareFoot;
                    newOrder.Tax          = (newOrder.MaterialCost + newOrder.LaborCost) * (newOrder.TaxRate / 100);
                    newOrder.Total        = newOrder.MaterialCost + newOrder.LaborCost + newOrder.Tax;

                    ConsoleIO.OrderHeader("Add an Order");
                    ConsoleIO.DisplayOrders(newOrder);
                    Console.WriteLine(ConsoleIO.SeparatorBar);
                    string answer = ConsoleIO.GetYesNoAnswerFromUser("Would you like to place this order?: ");
                    if (answer == "Y")
                    {
                        var createresponse = orderManager.CreateOrder(newOrder, ConsoleIO.OrderDate);
                        if (createresponse.Success)
                        {
                            Console.WriteLine("The order was placed!");
                            ConsoleIO.EnterKeyToContinue();
                        }
                        else
                        {
                            Console.WriteLine(createresponse.Message);
                            ConsoleIO.EnterKeyToContinue();
                        }
                    }
                    else
                    {
                        Console.WriteLine("The order was cancelled.");
                        ConsoleIO.EnterKeyToContinue();
                    }
                }
                else
                {
                    Console.WriteLine(productresponse.Message);
                    ConsoleIO.EnterKeyToContinue();
                }
            }

            else
            {
                Console.WriteLine(response.Message);
                ConsoleIO.EnterKeyToContinue();
            }
        }
Ejemplo n.º 22
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.º 23
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");
            }
        }
Ejemplo n.º 24
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()
        {
            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();
        }
Ejemplo n.º 26
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);
            }
        }
Ejemplo n.º 27
0
        public void Execute()
        {
            InputRules      inputManager   = new InputRules();
            OrderManager    manager        = OrderManagerFactory.Create();
            TaxStateManager stateManager   = TaxStateManagerFactory.Create();
            ProductManager  productManager = ProductManagerFactory.Create();
            Order           order          = new Order();
            DateTime        orderDate;
            string          stateInput, productInput, tempAreaInput;



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



            //Get order date file
            Console.WriteLine("Please enter the Order Date you would like to edit");
            while (!DateTime.TryParse(Console.ReadLine(), out orderDate))
            {
                Console.WriteLine("That is not a valid format, please try again");
            }



            //display all orders
            OrderLookupResponse fileResponse = manager.AllOrderLookup(orderDate);

            if (fileResponse.Success)
            {
                foreach (Order entry in fileResponse.Orders)
                {
                    ConsoleIO.DisplayOrder(entry);
                }
            }
            Console.WriteLine();



            //get order number and make edits
            int orderNumberInput;

            Console.WriteLine("Enter the Order Number you'd like to edit:");
            while (!int.TryParse(Console.ReadLine(), out orderNumberInput))
            {
                Console.WriteLine("That is not a valid input.  Try again");
            }
            OrderLookupResponse response = manager.OrderLookup(orderDate, orderNumberInput);

            if (response.Success)
            {
                ConsoleIO.DisplayOrder(response.Order);
                order = response.Order;
                Console.WriteLine();

                Console.WriteLine("Please enter new values, entering nothing will keep current value.");



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



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

                //Edit State
                TaxStateLookupResponse  stateResponse      = new TaxStateLookupResponse();
                StateInputCheckResponse stateInputResponse = new StateInputCheckResponse();

                Console.WriteLine("Please enter new values, entering nothing will keep current value.");

                Console.Write("State: ");
                stateInput         = Console.ReadLine();
                stateInputResponse = inputManager.StateCheck(stateInput);
                if (stateInputResponse.Success)
                {
                    stateResponse.Success = false;
                    while (!stateResponse.Success)
                    {
                        stateResponse = stateManager.FindTaxState(stateInput);
                        if (!stateResponse.Success)
                        {
                            Console.WriteLine(stateResponse.Message);
                            Console.Write("State: ");
                            stateInput = Console.ReadLine();
                        }
                    }
                    order.State = stateInput;
                }
                Console.Clear();



                //Display Products
                Console.WriteLine("These are the materials availbale to choose from:");
                foreach (Product entry in productManager.GetProducts())
                {
                    Console.WriteLine(string.Format("{0},  Labor Cost: {1},  Material Cost: {2}",
                                                    entry.ProductType,
                                                    entry.LaborCostPerSquareFoot,
                                                    entry.CostPerSquareFoot));
                }

                //Edit Product
                ProductLookupResposnse    productResponse      = new ProductLookupResposnse();
                ProductInputCheckResponse productInputResponse = new ProductInputCheckResponse();
                Console.WriteLine("Please enter new values, entering nothing will keep current value.");

                Console.Write("Product Type: ");
                productInput         = Console.ReadLine();
                productInputResponse = inputManager.ProductCheck(productInput);
                if (productInputResponse.Success)
                {
                    productResponse.Success = false;
                    while (!productResponse.Success)
                    {
                        productResponse = productManager.FindProduct(productInput);
                        if (!productResponse.Success)
                        {
                            Console.WriteLine(productResponse.Message);
                            Console.Write("Product Type: ");
                            productInput = Console.ReadLine();
                        }
                    }
                    order.ProductType = productInput;
                }
                Console.Clear();



                //Edit Area
                AreaCheckResponse areaResponse = new AreaCheckResponse();
                Console.Write("Area: ");
                decimal areaInput;
                tempAreaInput = Console.ReadLine();
                if (tempAreaInput != "")
                {
                    areaResponse.Success = false;
                    while (!decimal.TryParse(tempAreaInput, out areaInput))
                    {
                        Console.WriteLine("That is not a valid input.");
                        Console.Write("Area: ");
                        tempAreaInput = Console.ReadLine();
                    }
                    while (!areaResponse.Success)
                    {
                        areaResponse = inputManager.AreaCheck(areaInput);
                        Console.WriteLine(areaResponse.Message);
                    }
                    order.Area = areaInput;
                }
                Console.Clear();



                if (stateInput == "" && productInput == "" && tempAreaInput == "")
                {
                    order = OrderCreation.EditedOrder(order.OrderDate, order.OrderNumber, order.CustomerName, order.State, order.StateAbv, order.TaxRate, order.ProductType, order.Area, order.CostPerSqaureFoot, order.LaborCostPerSquareFoot, order.MaterialCost, order.LaborCost, order.Tax, order.Total);
                }
                else
                {
                    order = OrderCreation.CreateOrder(order.OrderDate, order.OrderNumber, order.CustomerName, order.State, order.ProductType, order.Area);
                }
                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.UpdateOrder(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;
            }
            else
            {
                Console.WriteLine("That Order does not currently exist in our system");
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
                return;
            }
        }
        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.º 29
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()
        {
            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();
        }