public void UpdateOrderInformation(Order selectedOrder)
        {
            Console.WriteLine(
                "To edit the order, enter a new value for each field or leave blank to keep the existing one...");
            Console.WriteLine();

            Console.Write("First Name ({0})", selectedOrder.Name);  //UpdateName method
            string userInput = Console.ReadLine();
            if (!string.IsNullOrEmpty(userInput))
                selectedOrder.Name = userInput;

            bool isValidState = false;       //  UpdateState method
            do
            {
            Console.Write("State ({0})", selectedOrder.State);
            userInput = Console.ReadLine().ToUpper();
            var taxLoader = new TaxRepository();
            List<Tax> taxList = taxLoader.LoadTaxesAndStatesFromFile();
            if (!string.IsNullOrEmpty(userInput)&&(taxList.Exists(t=>t.State==userInput)))
            {
                isValidState = true;
                selectedOrder.State = userInput;
                UpdateTaxRate(selectedOrder);
                UpdateCosts(selectedOrder);
            }
            else if (string.IsNullOrEmpty(userInput))
            {
                break;
            }
            else
            {
                Console.WriteLine("{0} is not a valid entry for State. We operate in:", userInput);
                foreach (var tax in taxList)
                {
                    Console.WriteLine("{0}", tax.State);
                }
            }

            } while (!isValidState);

            bool isValidProduct = false;  //update Product Method
            do
            {
                Console.Write("Product Type ({0})", selectedOrder.ProductType);
                userInput = Console.ReadLine();
                var productLoader = new ProductRespository();
                List<Product> productList = productLoader.LoadProductsFromFile();
                if (!string.IsNullOrEmpty(userInput) && (productList.Exists(p => p.ProductType.ToUpper() == userInput.ToUpper())))
                {
                    isValidProduct = true;
                    selectedOrder.ProductType = userInput;
                    UpdateProductInfo(selectedOrder);
                    UpdateCosts(selectedOrder);
                }
                else if (string.IsNullOrEmpty(userInput))
                {
                    break;
                }
                else
                {
                    Console.WriteLine("{0} is not in our inventory. We carry the following products: ", userInput);
                    foreach (var product in productList)
                    {
                        Console.WriteLine("{0}",product.ProductType );
                    }
                }

            } while (!isValidProduct);

            Console.Write("Area - ({0}):", selectedOrder.Area); //updateArea method
            userInput = Console.ReadLine();
            if (!string.IsNullOrEmpty(userInput))
            {
                bool res;
                decimal userArea;
                do
                {
                   // Console.Write("Area: ({0})", selectedOrder.Area);
                   // userInput = Console.ReadLine();

                    res = decimal.TryParse(userInput, out userArea);
                    if (!res)
                    {
                        Console.WriteLine("Invalid choice");
                        Console.Write("Area - ({0}):", selectedOrder.Area);
                        userInput = Console.ReadLine();
                        res = decimal.TryParse(userInput, out userArea);
                    }

                } while (!res);
                selectedOrder.Area = userArea;
                UpdateCosts(selectedOrder);

            }
            ConfirmAndUpdateOrder(selectedOrder);
        }
Esempio n. 2
0
        private void GetProductAndCostAndLaborPerSqFt(Order newOrder)
        {
            var productLoader = new ProductRespository();
            List<Product> productList = productLoader.LoadProductsFromFile();
            int count = 0;

            bool isNotValidProduct = true;//changing to product
            do
            {
                Console.WriteLine("\nThese are the products we carry:");

                foreach (var p in productList)
                {
                    Console.WriteLine("{0}", p.ProductType);
                }
                Console.Write("Enter what kind of floor you want: ");
                string userInput = Console.ReadLine();

                foreach (var product in productList)
                {

                    if (product.ProductType.ToUpper() == userInput.ToUpper())
                    {
                        count++;
                        newOrder.ProductType = product.ProductType;
                        newOrder.CostPerSquareFoot = product.CostPerSqauareFoot;
                        newOrder.LaborCostPerSquareFoot = product.LaborCostPerSquareFoot;
                        isNotValidProduct = false;

                    }

                }

                if (count == 0)
                {
                    Console.Clear();
                    Console.WriteLine("We don't carry {0}. Please enter what kind of floor you want: ", userInput);
                }

            } while (isNotValidProduct);
        }
        private void UpdateProductInfo(Order selectedOrder)
        {
            var p = new ProductRespository();
            var prodList = p.LoadProductsFromFile();
            var prod = prodList.Find(y => y.ProductType.ToUpper() == selectedOrder.ProductType.ToUpper());
            selectedOrder.ProductType = prod.ProductType;

            selectedOrder.CostPerSquareFoot = prod.CostPerSqauareFoot;
            selectedOrder.LaborCostPerSquareFoot = prod.LaborCostPerSquareFoot;

            var c = new Calculator();
            c.CalcuateValues(selectedOrder);
        }