Ejemplo n.º 1
0
        // Displays all the orders based off of order date
        public OrdersDisplayResponse DisplayOrders(string orderDate)
        {
            OrdersDisplayResponse response = new OrdersDisplayResponse {
                Orders = _orderRepository.LoadOrders(orderDate)
            };

            // Checks the date is valid
            if (!DateHandler.IsValidDate(orderDate))
            {
                response.Success = false;
                response.Code    = ErrorCode.NotAValidDate;
                return(response);
            }

            // LoadOrders returns null if it can't find a file
            if (response.Orders == null)
            {
                response.Success = false;
                response.Code    = ErrorCode.CouldNotFindFile;
                return(response);
            }

            // LoadOrders returns an order with number -1 if the file it's reading from is corrupt
            if (response.Orders.Any(x => x.Number == -1))
            {
                response.Success = false;
                response.Code    = ErrorCode.CorruptFile;
                return(response);
            }

            // If no orders were added to the list, the file is empty
            if (response.Orders.Count() == 0)
            {
                response.Success = false;
                response.Code    = ErrorCode.FileIsEmpty;
                return(response);
            }

            response.Success = true;


            return(response);
        }
Ejemplo n.º 2
0
        public void Execute()
        {
            ConsoleIO    prompt       = new ConsoleIO();
            List <Order> orders       = new List <Order>();
            OrderManager orderManager = OrderManagerFactory.Create();

            Console.Clear();
            Console.WriteLine("Display Orders");
            Console.WriteLine("**************");
            _orderDate = prompt.GetOrderDate();

            // Sends the order date off to the order manager to display the orders
            OrdersDisplayResponse response = orderManager.DisplayOrders(_orderDate);

            if (response.Success)
            {
                PrintOrders(response.Orders);
                prompt.PressEnterToContinue();
            }
            else
            {
                prompt.PrintError(response.Code);
            }
        }