Example #1
0
        internal static void Execute()
        {
            Console.Clear();
            Console.WriteLine("Add an Order ");
            Console.WriteLine("*************************************");
            Console.WriteLine();

            OrderManager manager = OrderManagerFactory.Create();

            DateTime orderDate    = ConsoleIO.GetFutureDateTime("Enter a valid Date EX: MM/DD/YYYY ");
            string   customerName = ConsoleIO.GetStringFromUser("Customer Name: ");

            TaxLookupResponse taxResponse = manager.LoadTaxes();
            var state = ConsoleIO.GetStateFromUser("State: ", taxResponse.Taxes);

            IEnumerable <Product> GetProducts = manager.GetAllProducts();

            ConsoleIO.ShowListOfProducts(GetProducts);

            ProductLookupResponse productResponse = manager.LoadProducts();
            var     productType = ConsoleIO.GetProductFromUser("Product Type: ", productResponse.Products);
            decimal area        = ConsoleIO.GetAreaFromUser("Area: ");

            Console.WriteLine();
            Console.WriteLine("*************************************");


            AddAnOrderResponse addResponse = manager.AddOrder(orderDate, customerName, state, productType, area, 0);

            if (!addResponse.Success)
            {
                Console.WriteLine("An error has occured");
                Console.WriteLine(addResponse.Message);
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
            else
            {
                Console.WriteLine($"Customer Name: {customerName}, State: {state.Abbreviation}, Product Type: {productType.Name}, Area: {area}");
                Console.WriteLine();
                if (ConsoleIO.GetYesNoAnswerFromUser($"Are you sure you want to add this file?") == "Y")
                {
                    manager.AddToOrderRepo(addResponse.AddedOrder);
                    Console.WriteLine("The Order was successfully added.");
                    Console.WriteLine("Press any key to continue...");
                }
                else
                {
                    Console.WriteLine("Order cancelled. Press any key to continue.");
                    Console.WriteLine("Press any key to continue...");
                }
                Console.ReadLine();
            }
        }
Example #2
0
        public TaxLookupResponse LoadTaxes()
        {
            TaxLookupResponse taxResponse = new TaxLookupResponse();

            taxResponse.Taxes = _taxRepository.GetTaxes();

            if (taxResponse.Taxes == null)
            {
                taxResponse.Success = false;
                taxResponse.Message = "Is not a state we sell in";
            }
            else
            {
                taxResponse.Success = true;
            }
            return(taxResponse);
        }
        public static void Execute()
        {
            Console.Clear();
            Console.WriteLine("Edit Order");
            Console.WriteLine("*************************************");

            OrderManager manager = OrderManagerFactory.Create();

            var userDateTimeInPut = ConsoleIO.GetDateTimeFromUser();
            OrderDateLookupResponse orderDateResponse = manager.OrderLookupDate(userDateTimeInPut);

            if (orderDateResponse.Success)
            {
                foreach (var order in orderDateResponse.ListOfOrders)
                {
                    Console.WriteLine($"Order Number: {order.OrderNumber}, Customer Name: {order.CustomerName}, State {order.State}, Tax Rate: {order.TaxRate}, Area: {order.Area}, Cost Per Square Foot: {order.CostPerSquareFoot}, Labor Cost Per Square Foot: {order.LaborCostPerSquareFoot}, Material Cost: {order.MaterialCost}, Labor Cost: {order.LaborCost}, Tax Total: {order.TotalTax}, Total Cost: {order.TotalCost}");
                }
                int number = ConsoleIO.GetOrderNumber("Enter the Order number do you want to edit?");

                var   originalOrder = new Order(orderDateResponse.ListOfOrders.SingleOrDefault(f => f.OrderNumber == number));
                Order updatedOrder  = new Order(originalOrder);

                TaxLookupResponse     taxesResponse   = manager.LoadTaxes();
                ProductLookupResponse productResponse = manager.LoadProducts();

                Console.Clear();
                updatedOrder.OrderDate    = userDateTimeInPut;
                updatedOrder.CustomerName = ConsoleIO.EditGetStringFromUser(updatedOrder, $"(Previous Name: {originalOrder.CustomerName}) Enter Customer Name: ");

                updatedOrder.State       = ConsoleIO.EditGetStateFromUser(updatedOrder, $"(Previous State: {originalOrder.State}) State: ", taxesResponse.Taxes);
                updatedOrder.ProductType = ConsoleIO.EditGetProductFromUser(updatedOrder, $"(Previous Type: {originalOrder.ProductType}) Product Type: ", productResponse.Products);
                updatedOrder.Area        = ConsoleIO.EditGetAreaFromUser(updatedOrder, $"(Previous Area: {originalOrder.Area}) Area: ");

                Console.WriteLine($"Customer Name: {updatedOrder.CustomerName}, State: {updatedOrder.State}, Product Type: {updatedOrder.ProductType}, Area: {updatedOrder.Area}");
                Console.WriteLine();
                if (ConsoleIO.GetYesNoAnswerFromUser($"Are you sure you want to add this file?") == "Y")
                {
                    EditOrderResponse editResponse = manager.EditOrder(updatedOrder);
                    if (editResponse.Success)
                    {
                        Console.WriteLine("The Order was successfully updated.");
                        Console.WriteLine("Press any key to continue...");
                    }
                    else
                    {
                        Console.WriteLine("An error occurred.");
                        Console.WriteLine(editResponse.Message);
                    }
                }
                else
                {
                    Console.WriteLine("Edit order was cancelled. Press any key to continue.");
                }
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("An error has occurred");
                Console.WriteLine(orderDateResponse.Message);
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
        }