Exemplo n.º 1
0
        public GetDateResponse GetDate(string date)
        {
            GetDateResponse response = new GetDateResponse();

            DateTime validate = new DateTime();

            if (DateTime.TryParse(date, out validate))
            {
                string path = validate.ToString("MMddyyyy");

                if (File.Exists(Settings.GetOrderDateFilePath(path)))
                {
                    response.Success    = true;
                    response.FilePath   = Settings.GetOrderDateFilePath(path);
                    response.Date       = path;
                    response.FileExists = true;
                    return(response);
                }
                else
                {
                    response.Success    = true;
                    response.Message    = "The date given does not match any record on file.";
                    response.FileExists = false;
                    return(response);
                }
            }
            else
            {
                response.Success = false;
                response.Message = "That was not a date in MM/DD/YYYY format.";
                return(response);
            }
        }
Exemplo n.º 2
0
        public GetDateResponse FindOrdersOnDate(string date, FunctionType type)
        {
            GetDateResponse response = new GetDateResponse();

            IGetDate getDate = GetDateRuleFactory.Create(type);

            response = getDate.GetDate(date);

            return(response);
        }
Exemplo n.º 3
0
        public void CanListOrders(string date, bool expected)
        {
            OrderManager        manager  = OrderManagerFactory.Create();
            TestOrderRepository testRepo = new TestOrderRepository();
            GetDateResponse     response = manager.FindOrdersOnDate(date, FunctionType.DisplayOrders);
            List <Order>        orders   = manager.RetrieveOrdersOnDate(response);
            List <Order>        control  = testRepo.LoadOrders("01012019");
            bool actual = control.Equals(orders);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 4
0
        public void CanOnlyAssignValidOrderNumbers(string date, bool expected)
        {
            OrderManager           manager  = OrderManagerFactory.Create();
            Order                  order    = new Order();
            GetDateResponse        response = manager.FindOrdersOnDate(date, FunctionType.DisplayOrders);
            List <Order>           orders   = manager.RetrieveOrdersOnDate(response);
            GetOrderNumberResponse number   = manager.AssignOrderNumber(orders);

            order.OrderNumber = number.OrderNumber;
            bool actual = (order.OrderNumber == 1 && orders == null || order.OrderNumber == orders.Max(o => o.OrderNumber) + 1);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 5
0
        public void CanSelectOrderWithOrderNumber(string date, string orderNumber, bool expected)
        {
            OrderManager           manager  = OrderManagerFactory.Create();
            GetDateResponse        response = manager.FindOrdersOnDate(date, FunctionType.DisplayOrders);
            List <Order>           orders   = manager.RetrieveOrdersOnDate(response);
            GetOrderNumberResponse number   = manager.SelectOrderWithOrderNumber(orderNumber);
            bool actual = number.Success;

            foreach (Order o in orders)
            {
                if (number.OrderNumber == o.OrderNumber)
                {
                    actual = true;
                    break;
                }
                else
                {
                    continue;
                }
            }
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 6
0
        public void Execute()
        {
            OrderManager manager = OrderManagerFactory.Create();

            bool            validInput = false;
            GetDateResponse response   = null;

            while (!validInput)
            {
                string date = Query.GetDateFromUser();
                response = manager.FindOrdersOnDate(date, FunctionType.DisplayOrders);
                if (response.Success && !response.FileExists)
                {
                    validInput = true;
                    Alert.AlertUserInvalidInput(response);
                }
                else if (response.Success)
                {
                    validInput = true;
                }
                else
                {
                    Alert.AlertUserInvalidInput(response);
                }
            }

            if (response.FileExists)
            {
                List <Order> ordersFromFile = manager.RetrieveOrdersOnDate(response);

                foreach (Order order in ordersFromFile)
                {
                    order.DisplayOrdersFormat(response.Date);
                }

                Prompt.PressKeyToContinue();
            }
        }
Exemplo n.º 7
0
        public void Execute()
        {
            OrderManager manager = OrderManagerFactory.Create();

            bool            validDate    = false;
            GetDateResponse dateResponse = null;

            while (!validDate)
            {
                string date = Query.GetDateFromUser();
                dateResponse = manager.FindOrdersOnDate(date, FunctionType.RemoveOrder);
                if (dateResponse.Success)
                {
                    validDate = true;
                }
                else
                {
                    Alert.AlertUserInvalidInput(dateResponse);
                }
            }

            if (dateResponse.FileExists)
            {
                List <Order>           orders = manager.RetrieveOrdersOnDate(dateResponse);
                GetOrderNumberResponse orderNumberResponse = null;

                bool  validOrderNumber = false;
                Order order            = null;

                while (!validOrderNumber)
                {
                    string orderNumber = Query.GetOrderNumberFromUser();
                    orderNumberResponse = manager.SelectOrderWithOrderNumber(orderNumber);
                    if (orderNumberResponse.Success)
                    {
                        foreach (Order o in orders)
                        {
                            if (o.OrderNumber == orderNumberResponse.OrderNumber)
                            {
                                order            = o;
                                validOrderNumber = true;
                            }
                            else
                            {
                                continue;
                            }
                        }
                        if (!validOrderNumber)
                        {
                            Alert.OrderNumberNotOnList(orderNumberResponse.OrderNumber);
                        }
                    }
                    else
                    {
                        Alert.AlertUserInvalidInput(orderNumberResponse);
                    }
                }

                bool confirmingRemove = true;

                while (confirmingRemove)
                {
                    Console.Clear();
                    order.DisplayOrdersFormat(dateResponse.Date);
                    if (Prompt.ConfirmChanges(3))
                    {
                        if (Prompt.IsUserSure())
                        {
                            orders.Remove(order);

                            manager.SaveOrdersToFile(orders, dateResponse.FilePath);

                            confirmingRemove = false;
                        }
                        else
                        {
                            confirmingRemove = false;
                        }
                    }
                    else
                    {
                        confirmingRemove = false;
                    }
                }
            }
        }
Exemplo n.º 8
0
        public List <Order> RetrieveOrdersOnDate(GetDateResponse response)
        {
            List <Order> orders = OrderRepository.LoadOrders(response.Date);

            return(orders);
        }
Exemplo n.º 9
0
        public void Execute()
        {
            OrderManager manager = OrderManagerFactory.Create();

            bool            validInput = false;
            GetDateResponse response   = null;

            while (!validInput)
            {
                string date = Query.GetDateFromUser();
                response = manager.FindOrdersOnDate(date, FunctionType.AddOrder);
                if (response.Success)
                {
                    validInput = true;
                }
                else
                {
                    Alert.AlertUserInvalidInput(response);
                }
            }

            if (response.FileExists)
            {
                List <Order> ordersFromFile = manager.RetrieveOrdersOnDate(response);

                Order order          = CreateNewOrder();
                bool  confirmingSave = true;
                bool  willSave       = false;

                while (confirmingSave)
                {
                    Console.Clear();
                    order.AddOrderFormat();
                    willSave = Prompt.ConfirmChanges(1);
                    if (!willSave)
                    {
                        confirmingSave = Prompt.IsUserSure();
                    }
                    else
                    {
                        confirmingSave = false;
                    }
                }

                if (willSave)
                {
                    GetOrderNumberResponse saveResponse = manager.AssignOrderNumber(ordersFromFile);

                    if (saveResponse.Success)
                    {
                        order.OrderNumber = saveResponse.OrderNumber;
                        ordersFromFile.Add(order);
                        manager.SaveOrdersToFile(ordersFromFile, response.FilePath);
                    }
                    else
                    {
                        Alert.AlertUserInvalidInput(saveResponse);
                    }
                }
            }
            else
            {
                List <Order> newOrderList = new List <Order>();

                Order order          = CreateNewOrder();
                bool  confirmingSave = true;
                bool  willSave       = false;

                while (confirmingSave)
                {
                    Console.Clear();
                    order.AddOrderFormat();
                    willSave = Prompt.ConfirmChanges(1);
                    if (!willSave)
                    {
                        confirmingSave = Prompt.IsUserSure();
                    }
                    else
                    {
                        confirmingSave = false;
                    }
                }

                if (willSave)
                {
                    var fs = File.Create(response.FilePath);
                    fs.Close();
                    order.OrderNumber = 1;
                    newOrderList.Add(order);
                    manager.SaveOrdersToFile(newOrderList, response.FilePath);
                }
            }
        }
Exemplo n.º 10
0
        public void Execute()
        {
            OrderManager manager = OrderManagerFactory.Create();

            bool            validInput   = false;
            GetDateResponse dateResponse = null;

            while (!validInput)
            {
                string date = Query.GetDateFromUser();
                dateResponse = manager.FindOrdersOnDate(date, FunctionType.EditOrder);
                if (dateResponse.Success)
                {
                    validInput = true;
                }
                else
                {
                    Alert.AlertUserInvalidInput(dateResponse);
                }
            }

            if (dateResponse.FileExists)
            {
                List <Order> orders = manager.RetrieveOrdersOnDate(dateResponse);

                foreach (Order o in orders)
                {
                    GetProductResponse fillInProducts = manager.AssignProductInfo(o.ProductType, FunctionType.EditOrder);
                    GetTaxesResponse   fillInTaxes    = manager.AssignTaxInfo(o.State, FunctionType.EditOrder);

                    o.Product = fillInProducts.Product;
                    o.Taxes   = fillInTaxes.Taxes;
                }

                GetOrderNumberResponse orderNumberResponse = null;

                bool validOrderNumber = false;
                int  index            = int.MinValue;

                while (!validOrderNumber)
                {
                    string orderNumber = Query.GetOrderNumberFromUser();
                    orderNumberResponse = manager.SelectOrderWithOrderNumber(orderNumber);
                    if (orderNumberResponse.Success)
                    {
                        if (orders.Exists(o => o.OrderNumber == orderNumberResponse.OrderNumber))
                        {
                            index            = orders.FindIndex(o => o.OrderNumber == orderNumberResponse.OrderNumber);
                            validOrderNumber = true;
                        }
                        else
                        {
                            Alert.OrderNumberNotOnList(orderNumberResponse.OrderNumber);
                        }
                    }
                    else
                    {
                        Alert.AlertUserInvalidInput(orderNumberResponse);
                    }
                }

                QueryUserEditName(manager, orders, index);
                QueryUserEditTaxes(manager, orders, index);
                QueryUserEditProducts(manager, orders, index);
                QueryUserEditArea(manager, orders, index);

                bool confirmingSave = true;
                bool willSave       = false;

                while (confirmingSave)
                {
                    Console.Clear();
                    orders[index].DynamicDisplayFormat();
                    willSave = Prompt.ConfirmChanges(2);
                    if (!willSave)
                    {
                        confirmingSave = Prompt.IsUserSure();
                    }
                    else
                    {
                        confirmingSave = false;
                    }
                }

                if (willSave)
                {
                    manager.SaveOrdersToFile(orders, dateResponse.FilePath);
                }
            }
        }