Ejemplo n.º 1
0
        public void Execute()
        {
            Console.Clear();

            OrderManager orderManager = OrderManagerFactory.Create();

            Console.WriteLine("Remove Order");
            Console.WriteLine("************");
            _orderDate   = prompt.GetOrderDate();
            _orderNumber = prompt.GetOrderNumber();

            // Sends the order date and order number off to the order manager to get the order requested
            GetOrderResponse getOrderResponse = orderManager.GetOrder(_orderDate, _orderNumber);

            if (!getOrderResponse.IsValidDate)
            {
                prompt.PrintError(ErrorCode.NotAValidDate);
            }
            else if (!getOrderResponse.IsFutureDate)
            {
                prompt.PrintError(ErrorCode.NotAFutureDate);
            }
            else if (!getOrderResponse.Success)
            {
                prompt.PrintError(getOrderResponse.Code);
            }
            else
            {
                // Sends the order to the order manager for validation
                ValidateRemoveOrderResponse response = orderManager.ValidateRemoveOrder(_orderDate, getOrderResponse.Order);

                if (!response.Success)
                {
                    prompt.PrintError(response.Code);
                }
                else
                {
                    // Prints the order to be removed to the screen for confirmation
                    prompt.PrintOrder(_orderDate, getOrderResponse.Order);
                    // Gets confirmation on whether to remove or not
                    do
                    {
                        _code = prompt.GetConfirmation("remove");
                    } while (_code == YesNo.Invalid);
                    // If user decides not to remove, print that to the screen
                    if (_code == YesNo.No)
                    {
                        prompt.PrintError(ErrorCode.DidntConfirmOrder);
                    }
                    else
                    {
                        // Sends the orders list to the order manager to be written to the file
                        orderManager.RemoveOrder(response.Orders);
                        prompt.PrintSuccessMessage("Order removed successfully.");
                    }
                }
            }
        }
        public void RemoveOrderValidation(int orderNumber, string orderDate, string customerName, string state, string productType, decimal area, bool expectedResult)
        {
            IOrderRepository _orderRepository = new OrderProdRepository();
            OrderManager     _orderManager    = OrderManagerFactory.Create();
            Order            order            = new Order {
                Number       = orderNumber,
                CustomerName = customerName,
                State        = state,
                ProductType  = productType,
                Area         = area
            };

            ValidateRemoveOrderResponse response = _orderManager.ValidateRemoveOrder
                                                       (orderDate, order);

            Assert.AreEqual(expectedResult, response.Success);
        }
Ejemplo n.º 3
0
        // Takes the order to be removed and the order date
        public ValidateRemoveOrderResponse ValidateRemoveOrder(string orderDate, Order order)
        {
            ValidateRemoveOrderResponse response = new ValidateRemoveOrderResponse {
                Orders = _loadedOrders
            };


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

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

            // Checks if LoadOrders order list has an order number that matches the order passed in
            if (!response.Orders.Any(x => x.Number == order.Number))
            {
                response.Success = false;
                response.Code    = ErrorCode.OrderNumberDoesNotExist;
                return(response);
            }

            response.Success = true;

            // Gets the index where the order number matches the order in the list
            int index = response.Orders.FindIndex(x => x.Number == order.Number);

            response.Orders.RemoveAt(index); // Removes the order at the index

            return(response);
        }