Пример #1
0
        public Response<List<Order>> GetOrders(DateTime orderDate)
        {
            var repo = new OrderRepository();
            var response = new Response<List<Order>>();

            try
            {
                var orderList = repo.LoadOrders(orderDate);

                if (orderList == null)
                {
                    response.Success = false;
                    response.Message = "Order not found!";
                }
                else
                {
                    response.Success = true;
                    response.Data = orderList;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return response;
        }
        public Order CreateEditOrder(Response<Order> editingOrder)
        {
            editingOrder.Data.OrderNumber = orderNumber;
            editingOrder.Data.CustomerName = UserPrompts.GetCustomerNameForEdit(editingOrder.Data.CustomerName);
            editingOrder.Data.ProductType = UserPrompts.GetProductTypeForEdit(editingOrder.Data.ProductType);
            editingOrder.Data.Area = UserPrompts.GetAreaForEdit(editingOrder.Data.Area);
            editingOrder.Data.State = UserPrompts.GetStateForEdit(editingOrder.Data.State);

            return editingOrder.Data;
        }
Пример #3
0
        public Response<Order> AddNewOrder(Order orderToAdd, DateTime orderDate)
        {
            var repo = new OrderRepository();
            var response = new Response<Order>();

            try
            {
                repo.Add(orderToAdd, orderDate);
                response.Success = true;
                response.Data = orderToAdd;
            }
            catch (Exception)
            {
                response.Success = false;
                response.Message = "The order could not be added. Please verify that inputs are correct.";
            }
            return response;
        }
        public void Execute()
        {
            DateTime removeDate = displayOrdersWorkflow.GetOrderDateFromUser();
            int orderNumber = editOrderWorkflow.GetOrderNumber();
            orderToRemove.OrderNumber = orderNumber;
            orderOps.GetOrders(removeDate);
            response = orderOps.GetOrderToEdit(removeDate, orderNumber);

            RemoveOrderToConfirm(response.Data, removeDate);

            if (response.Success)
            {
                Console.WriteLine("Order {0} has been deleted.", orderToRemove.OrderNumber);
            }
            else
            {
                Console.WriteLine(response.Message);
            }
        }
Пример #5
0
        public Response<Order> GetOrderToEdit(DateTime editDate, int orderNumber)
        {
            var repo = new OrderRepository();
            var response = new Response<Order>();

            try
            {
                var orderList = repo.LoadOrders(editDate);
                if (orderList == null)
                {
                    response.Success = false;
                    response.Message = "Sorry 'bout you";
                }
                else
                    {
                        var order = orderList.FirstOrDefault(o => o.OrderNumber == orderNumber);

                        if (order == null)
                        {
                            response.Success = false;
                            response.Message = "Sorry, that is an invalid entry.";
                        }
                        else
                        {
                            response.Success = true;
                            response.Data = order;
                        }
                    }

            }
            catch
                (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return response;
        }
Пример #6
0
        /// <summary>
        /// 
        /// </summary>checks to see if a date file already exists
        /// <param name="currentDate"></param>
        /// <returns></returns>
        public string CheckFileDate(DateTime currentDate)
        {
            string formattedDate = _repo.GetOrderFile(currentDate);
            List<Order> order = new List<Order>();
            Response response = new Response();
            Order newOrder = new Order();

            if (!File.Exists(formattedDate))
            {
                //newOrder.OrderNumber = 1;
                string formattedDateNew = _repo.CreateFile(currentDate);
                return formattedDateNew;
            }

            else
            {
                //_repo.WriteNewLine(newOrder, formattedDate);
                return formattedDate;

            }

            // Console.WriteLine("That date does not match a a date in our files");
            //write this error to the error log
        }
Пример #7
0
        public Response<Order> RemovePreEditedOrder(Order orderBeingRemoved, DateTime editDate)
        {
            var repo = new OrderRepository();
            var response = new Response<Order>();

            try
            {
                repo.Delete(orderBeingRemoved, editDate);
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = "Order could not be deleted; please enter information again.";
            }

            return response;
        }
Пример #8
0
        //calls CreateOrder and stores a Order in response.
        public void PopulateOrder(string formattedDate)
        {
            OrderOperations ops = new OrderOperations();
            var response = new Response();
            Order order = new Order();
            bool isValid = false;
            decimal stateRate = 0;
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Clear();
            Console.WriteLine("\tEnter Account Information");
            Console.WriteLine("\t----------------------");
            Console.ForegroundColor = ConsoleColor.White;

            bool checkedInput = true;
            do
            {
                Console.Write("\tLast Name: ");
                order.LastName = Console.ReadLine();
                if (order.LastName.Length <= 0)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("\tThat was not a valid entry.\n\t Please enter a name...");
                    log.ErrorMessage = "That was not a valid name(name) UI:PopulateOrder/AddWorkflow....";
                    ops.CallingErrorLogRepository(log.ErrorMessage);
                    checkedInput = false;
                    continue;
                }

                checkedInput = ops.ValidateInput(order.LastName.ToCharArray());

                if (checkedInput == false)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("\tNo special characters in name are permitted.\n\t Please enter valid name");
                    log.ErrorMessage = "That was not a valid name(name) UI:PopulateOrder/AddWorkflow....";
                    ops.CallingErrorLogRepository(log.ErrorMessage);
                }

                else
                {
                    checkedInput = true;
                }

            } while (checkedInput == false);

            do
            {
                Console.ForegroundColor = ConsoleColor.White;

                Console.Write("\tState: ");
                order.State = Console.ReadLine();
                //string state = order.State;
                if (order.State.Length < 2)
                {
                    Console.WriteLine("\tThat was not a valid entry.\n Please enter a state...");
                    log.ErrorMessage = "That was not a valid entry(state) UI:PopulateOrder/AddWorkflow....";
                    ops.CallingErrorLogRepository(log.ErrorMessage);
                }
                else
                {
                    isValid = true;
                    stateRate = ops.MatchState(order.State);
                    if (stateRate == 0)
                    {
                        isValid = false;
                    }
                }
            } while (!isValid);

            //setting tax rate based on state
            order.TaxRate = stateRate;
            Console.ForegroundColor = ConsoleColor.White;

            Console.WriteLine("\tYour tax rate is {0}: ", order.TaxRate);

            //-------------PRODUCT-----------------------

            Product product = new Product();
            do
            {
                Console.ForegroundColor = ConsoleColor.White;

                //Console.WriteLine("");
                Console.Write("\tPlease enter a product type:\n\t\t Carpet, Laminate, Tile, Wood: ");

                order.ProductType = Console.ReadLine();

                if (order.ProductType.Length > 8 || order.ProductType.Length < 1)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("\tThat was not a valid entry.\n Please enter a product...");
                    log.ErrorMessage = "That was not a valid entry (product) UI:PopulateOrder....";
                    ops.CallingErrorLogRepository(log.ErrorMessage);
                }
                else
                {

                    order.CostSqFt = ops.ReturnCostPerSquareFoot(order.ProductType);

                }
            } while (order.CostSqFt == 0);// is 0

            Console.ForegroundColor = ConsoleColor.White;

            Console.WriteLine("\tYour cost per square foot is {0:c}: ", order.CostSqFt);

            // getting labor per square foot
            order.LaborSqFt = ops.LaborPerSquareFt(order.ProductType);
            Console.ForegroundColor = ConsoleColor.White;

            Console.WriteLine("\tYour labor per square foot is {0:c}: ", order.LaborSqFt);

            // getting area
            do
            {
                Console.ForegroundColor = ConsoleColor.White;

                Console.Write("\tArea: ");
                string input = Console.ReadLine();
                if (input.Length == 0)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("\tThat was not a valid entry.\n\t Please enter a Area...");
                    log.ErrorMessage = "That was not a valid Area(Area) UI:PopulateOrder/AddWorkflow....";
                    ops.CallingErrorLogRepository(log.ErrorMessage);
                    order.Area = 0;
                    continue;
                }

                order.Area = decimal.Parse(input);

                if (order.Area <= 0)
                {
                    Console.WriteLine("\tYou need to get a bigger house!");
                    log.ErrorMessage = "That was not a valid area (area) UI:PopulateOrder....";
                    ops.CallingErrorLogRepository(log.ErrorMessage);

                }
            } while (order.Area <= 0);

            // getting material cost
            order.MaterialCost = ops.MaterialCost(order.ProductType, order.Area);
            Console.ForegroundColor = ConsoleColor.White;

            Console.Write("\tMaterial Cost: {0:c} ", order.MaterialCost);

            //getting labor cost
            Console.ForegroundColor = ConsoleColor.White;

            order.LaborCost = ops.LaborCost(order.ProductType, order.Area);
            Console.Write("\nLabor Cost: {0:c} ", order.LaborCost);

            //get tax
            Console.ForegroundColor = ConsoleColor.White;

            order.Tax = ops.Tax(order.State, order.MaterialCost);
            Console.Write("\nTax: {0:c} ", order.Tax);

            //get total
            Console.ForegroundColor = ConsoleColor.White;

            Console.Write("\nTotal: {0:c}", order.Total);
            order.Total = ops.Total(order.MaterialCost, order.Tax, order.LaborCost);

            Console.WriteLine();

            ops.CreateOrder(order, formattedDate);

            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Yellow;

            Console.WriteLine("\n\tHere is your new order information:  \n");
            DisplayOrderWorkflow dowf = new DisplayOrderWorkflow();
            dowf.PrintOrderInformation(order);
            Console.ForegroundColor = ConsoleColor.White;
        }
Пример #9
0
        public Response EditOrder(string formattedDate, int orderNumber, Order changedOrder)
        {
            Response response = new Response();
            _repo.GetEditedOrder(formattedDate, orderNumber, changedOrder);
            var revisedOrder = _repo.SortNewEditedFile(formattedDate, orderNumber);

            if (revisedOrder != null)
            {
                response.Success = true;
                response.OrderInfo = revisedOrder;
            }
            else
            {
                response.Success = false;
                Console.ForegroundColor = ConsoleColor.Red;

                response.Message = "The Edit was not sucessful in operations/EditOrder.";
                log.ErrorMessage = "That Edit was not sucessful  BLL:EditOrder....";
                CallingErrorLogRepository(log.ErrorMessage);
            }
            response.OrderInfo = revisedOrder;
            return response;
        }
Пример #10
0
 public void CreateOrder(Order order, string formattedDate)
 {
     Response response = new Response();
     _repo.WriteNewLine(order, formattedDate);
 }
Пример #11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="formattedDate"></param>
        /// <param name="orderNumber"></param>
        /// <returns></returns>
        public Response OrderToDelete(string formattedDate, int orderNumber)
        {
            var response = new Response();

            // Order deletedOrder = _repo.GetOrderNumber(formattedDate, orderNumber);
            bool deletedNum = _repo.DeleteOrder(formattedDate, orderNumber);

            if (deletedNum)
            {
                response.Success = true;
                response.Message = "The order you were trying to delete has been successfully deleted.";
            }
            else
            {
                //need to do as TRY CATCH ---IF reach here wil have entered something other than an order num
                response.Success = false;
                Console.ForegroundColor = ConsoleColor.Red;

                response.Message = "You were not able to delete that order.";
                log.ErrorMessage = "Not able to delete order  BLL:OrderToDel....";
                CallingErrorLogRepository(log.ErrorMessage);
            }
            return response;
        }
Пример #12
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="order"></param>
        /// <param name="formattedDate"></param>
        /// <returns></returns>
        public Response NewCustomerInformationResponse(Order order, string formattedDate)
        {
            var response = new Response();

            _repo.WriteNewLine(order, formattedDate);
            response.OrderInfo = order;

            return response;
        }
Пример #13
0
        /// <summary>
        /// validates the order date exists
        /// </summary>
        /// <param name="OrderDate"></param>
        /// <returns></returns>
        public string GetOrderDate(DateTime OrderDate)
        {
            List<Order> order = new List<Order>();
            Response response = new Response();
            string newFileName = _repo.GetOrderFile(OrderDate);

            if (File.Exists(newFileName))
            {
                response.Success = true;
                return newFileName;
            }
            else
            {
                response.Success = false;
                Console.ForegroundColor = ConsoleColor.Red;

                response.Message = "This is not the order date you are looking for...";
                log.ErrorMessage = "That was not the order date you are looking for BLL:GetOrderDate....";
                CallingErrorLogRepository(log.ErrorMessage);
                return null;
            }
        }
Пример #14
0
        /// <summary>
        /// brings back an order using the order number, validates the actual order number exists
        /// </summary>
        /// <param name="newFileName"></param>
        /// <param name="orderNumber"></param>
        /// <returns></returns>
        public Response GetOrder(string newFileName, int orderNumber)
        {
            var response = new Response();
            var order = _repo.GetOrderNumber(newFileName, orderNumber);

            if (order != null)
            {
                response.Success = true;
                response.OrderInfo = order;
            }
            else
            {
                response.Success = false;
                Console.ForegroundColor = ConsoleColor.Red;

                response.Message = "This is not the order number you are looking for...";
                log.ErrorMessage = "That was not the order number you are looking for BLL:GetOrder....";
                CallingErrorLogRepository(log.ErrorMessage);
            }

            return response;
        }
Пример #15
0
        public Order NewOrder()
        {
            OrderOperations ops = new OrderOperations();
            ////*************************************************************************************

            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Yellow;

            Console.WriteLine("\tHere is your new order information:  ");
            DisplayOrderWorkflow dowf = new DisplayOrderWorkflow();
            Response response = new Response();
            //dowf.DisplayOrderInformation(EditedOrder);
            //Order editedOrder = dowf.DisplayOrderInformation(formattedDate, orderNumber);
            Order newEditedOrder = response.OrderInfo;
            response = ops.EditOrder(formattedDate, orderNumber, _currentOrder);
            dowf.PrintOrderInformation(response.OrderInfo);
            Console.ForegroundColor = ConsoleColor.White;
            return newEditedOrder;
        }