Exemplo n.º 1
0
        public LoadOrderResponse LoadOrder(string orderDate, int orderNumber)
        {
            LoadOrderListResponse displayResponse = LoadOrderList(orderDate);
            LoadOrderResponse     loadResponse    = new LoadOrderResponse();

            if (displayResponse.Success)
            {
                foreach (Order order in displayResponse.Orders)
                {
                    if (order.OrderNumber == orderNumber)
                    {
                        loadResponse.Order   = order;
                        loadResponse.Success = true;
                    }
                }
                if (loadResponse.Order == null)
                {
                    loadResponse.Success = false;
                    loadResponse.Message = "An order with that order number was not found.";
                }
            }
            else
            {
                loadResponse.Success = false;
                loadResponse.Message = displayResponse.Message;
            }

            return(loadResponse);
        }
Exemplo n.º 2
0
        public void CanAddOrderToRepo(string customerName, string state, string type, int area, string orderDate, bool expectedResult)
        {
            OrderManager manager = OrderManagerFactory.Create();

            Order newOrder = new Order()
            {
                CustomerName = customerName,
                State        = state,
                FloorType    = type,
                Area         = area
            };

            LoadOrderResponse addResponse = manager.LoadNewOrder(newOrder, orderDate);

            Assert.AreEqual(expectedResult, addResponse.Success);

            if (addResponse.Success)
            {
                manager.AddNewOrder(newOrder, orderDate);

                LoadOrderListResponse response = manager.LoadOrderList("10/10/20");
                var orders = response.Orders;

                Order check = orders[1];

                Assert.AreEqual("Test Man", check.CustomerName);
                Assert.AreEqual("Tile", check.FloorType);
                Assert.AreEqual(105, check.Area);
            }
        }
Exemplo n.º 3
0
        public LoadOrderListResponse LoadOrders(string orderDate)
        {
            LoadOrderListResponse response = new LoadOrderListResponse();

            response.Orders  = _orders;
            response.Success = true;
            return(response);
        }
Exemplo n.º 4
0
        public LoadOrderListResponse LoadOrderList(string orderDate)
        {
            LoadOrderListResponse response = new LoadOrderListResponse();

            if (!_orderRepository.OrderFileExists(orderDate))
            {
                response.Success = false;
                response.Message = $"No orders were placed on {orderDate}";
            }
            else
            {
                response = _orderRepository.LoadOrders(orderDate);
            }
            return(response);
        }
Exemplo n.º 5
0
        public void Execute()
        {
            OrderManager manager = OrderManagerFactory.Create();

            Console.Clear();
            Console.WriteLine("Display Orders");
            Console.WriteLine("*********************************************");
            string orderDate = ConsoleIO.GetOrderDateFromUser("Enter the order date: ", true);

            LoadOrderListResponse orderListResponse = manager.LoadOrderList(orderDate);

            if (orderListResponse.Success)
            {
                int orderNumber = ConsoleIO.GetOrderNumberFromUser("Please enter the order number: ");
                int orderIndex  = orderNumber - 1;

                LoadOrderResponse orderResponse = manager.LoadOrder(orderDate, orderNumber);

                if (orderResponse.Success)
                {
                    Console.Clear();
                    ConsoleIO.PrintOrders(orderResponse.Order, orderDate);
                    Console.WriteLine();

                    Console.WriteLine("Are you sure you want to cancel this order? (Y/N)");
                    string confirm = Console.ReadLine().ToUpper();

                    if (confirm == "Y")
                    {
                        Console.WriteLine("This order has been cancelled.");
                        manager.RemoveOrder(orderIndex, orderDate);
                    }
                }
                else
                {
                    Console.WriteLine("An error occured: ");
                    Console.WriteLine(orderResponse.Message);
                }
            }
            else
            {
                Console.WriteLine("An error occured: ");
                Console.WriteLine(orderListResponse.Message);
            }

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Exemplo n.º 6
0
        public LoadOrderListResponse LoadOrders(string orderDate)
        {
            LoadOrderListResponse response = new LoadOrderListResponse();

            response.Success = true;
            response.Orders  = new List <Order>();

            string _filePath = GetFilePath(orderDate);

            try
            {
                using (StreamReader reader = new StreamReader(_filePath))
                {
                    reader.ReadLine();
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        Order newOrder = new Order();

                        string[] columns = line.Split(',');

                        newOrder.OrderNumber            = int.Parse(columns[0]);
                        newOrder.CustomerName           = columns[1];
                        newOrder.State                  = columns[2];
                        newOrder.TaxRate                = decimal.Parse(columns[3]);
                        newOrder.FloorType              = columns[4];
                        newOrder.Area                   = decimal.Parse(columns[5]);
                        newOrder.CostPerSquareFoot      = decimal.Parse(columns[6]);
                        newOrder.LaborCostPerSquareFoot = decimal.Parse(columns[7]);
                        newOrder.MaterialCost           = decimal.Parse(columns[8]);
                        newOrder.LaborCost              = decimal.Parse(columns[9]);
                        newOrder.Tax   = decimal.Parse(columns[10]);
                        newOrder.Total = decimal.Parse(columns[11]);

                        response.Orders.Add(newOrder);
                    }
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
Exemplo n.º 7
0
        public void CanLoadTestOrders()
        {
            OrderManager manager = OrderManagerFactory.Create();

            LoadOrderListResponse response = manager.LoadOrderList("10/10/20");

            Assert.IsNotNull(response.Orders);
            Assert.IsTrue(response.Success);
            Assert.AreEqual(1, response.Orders.Count());

            var orders = response.Orders;

            Order check = orders[0];

            Assert.AreEqual("Dave", check.CustomerName);
            Assert.AreEqual("Wood", check.FloorType);
            Assert.AreEqual(1046.925, check.Total);
            Assert.AreEqual(100, check.Area);
        }
Exemplo n.º 8
0
        public void Execute()
        {
            OrderManager manager = OrderManagerFactory.Create();

            ConsoleIO.DisplayOrdersHeader();
            string orderDate = ConsoleIO.GetOrderDateFromUser("Enter the order date: ", false);

            LoadOrderListResponse response = manager.LoadOrderList(orderDate);

            if (response.Success)
            {
                ConsoleIO.DisplayOrdersHeader();
                ConsoleIO.PrintOrders(response.Orders, orderDate);
            }
            else
            {
                Console.WriteLine("An error occured: ");
                Console.WriteLine(response.Message);
            }

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Exemplo n.º 9
0
        public void Execute()
        {
            OrderManager manager     = OrderManagerFactory.Create();
            bool         recalculate = false;

            ConsoleIO.EditOrderHeader();
            string orderDate = ConsoleIO.GetOrderDateFromUser("Please enter the order date: ", false);

            LoadOrderListResponse orderListResponse = manager.LoadOrderList(orderDate);

            if (orderListResponse.Success)
            {
                int orderNumber = ConsoleIO.GetOrderNumberFromUser("Please enter the order number: ");

                LoadOrderResponse orderResponse = manager.LoadOrder(orderDate, orderNumber);

                if (orderResponse.Success)
                {
                    Order editOrder = orderResponse.Order;

                    Order originalOrder = new Order()
                    {
                        OrderNumber  = editOrder.OrderNumber,
                        CustomerName = editOrder.CustomerName,
                        State        = editOrder.State,
                        FloorType    = editOrder.FloorType,
                        Area         = editOrder.Area,
                        MaterialCost = editOrder.MaterialCost,
                        LaborCost    = editOrder.LaborCost,
                        Tax          = editOrder.Tax,
                        Total        = editOrder.Total
                    };

                    ConsoleIO.EditOrderHeader();
                    ConsoleIO.PrintOrders(editOrder, orderDate);

                    Console.WriteLine("Would you like to edit the customer name? Press 'Y' to edit. Press any other key to skip");
                    string userInput = Console.ReadLine().ToUpper();
                    if (userInput == "Y")
                    {
                        editOrder.CustomerName = ConsoleIO.GetStringFromUser("Please enter the new customer name: ");
                    }

                    ConsoleIO.EditOrderHeader();
                    ConsoleIO.PrintOrders(editOrder, orderDate);

                    Console.WriteLine("Would you like to change the state where the work is being done? Press 'Y' to edit. Press any other key to skip.");
                    userInput = Console.ReadLine().ToUpper();
                    if (userInput == "Y")
                    {
                        ConsoleIO.PrintStateList();
                        editOrder.State = ConsoleIO.GetStateAbbreviationFromUser("Please enter the two letter abbreviation for the state where the work is being done: ");
                        recalculate     = true;
                    }

                    ConsoleIO.EditOrderHeader();
                    ConsoleIO.PrintOrders(editOrder, orderDate);

                    Console.WriteLine("Would you like to change the flooring material? Press 'Y' to edit. Press any other key to skip.");
                    userInput = Console.ReadLine().ToUpper();
                    if (userInput == "Y")
                    {
                        var products     = manager.GetProductsList().ProductList;
                        int productIndex = ConsoleIO.GetProductChoiceFromUser();
                        editOrder.FloorType = products[productIndex].FloorType;
                        recalculate         = true;
                    }

                    ConsoleIO.EditOrderHeader();
                    ConsoleIO.PrintOrders(editOrder, orderDate);

                    Console.WriteLine("Would you like to change the flooring area? Press 'Y' to edit. Press any other key to skip.");
                    userInput = Console.ReadLine().ToUpper();
                    if (userInput == "Y")
                    {
                        editOrder.Area = ConsoleIO.GetAreaFromUser("Please enter the new square footage: ");
                        recalculate    = true;
                    }

                    if (recalculate)
                    {
                        manager.CalculateOrderCosts(editOrder);
                    }

                    ConsoleIO.EditOrderHeader();
                    Console.WriteLine("Original Order: ");
                    ConsoleIO.PrintOrders(originalOrder, orderDate);

                    Console.WriteLine();

                    Console.WriteLine("Edits Made: ");
                    ConsoleIO.PrintOrders(editOrder, orderDate);

                    Console.WriteLine();

                    Console.WriteLine("Confirm changes to order? (Y/N)");
                    string confirm = Console.ReadLine().ToUpper();

                    if (confirm == "Y")
                    {
                        Console.WriteLine("Your changes have been made.");
                        manager.EditOrder(editOrder, editOrder.OrderNumber - 1, orderDate);
                    }
                }
                else
                {
                    Console.WriteLine("An error occured: ");
                    Console.WriteLine(orderResponse.Message);
                }
            }
            else
            {
                Console.WriteLine("An error occured: ");
                Console.WriteLine(orderListResponse.Message);
            }

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }