Esempio n. 1
0
        public Response<Order> AddOrder(Order order, DateTime date)
        {
            var repo = new OrderRepository();
            var response = new Response<Order>();

            if (repo.FileExists(date))
            {
                order.OrderNumber = repo.HighestOrderNumber(date) + 1;

                try
                {
                    repo.CreateOrder(order, date);

                    response.Success = true;

                    response.Data = order;
                }
                catch (Exception ex)
                {
                    response.Success = false;
                    response.Message = "There was an error adding the order: " + ex.Message;
                    repo.ErrorLogger(ex.Message);
                }

                return response;
            }

            else
            {
                order.OrderNumber = 1;

                try
                {
                    repo.CreateFile(date);
                    repo.CreateOrder(order, date, true);
                    response.Success = true;
                    response.Data = order;
                }
                catch (Exception ex)
                {
                    response.Success = false;
                    response.Message = "There was an error adding the order: " + ex.Message;
                    repo.ErrorLogger(ex.Message);
                }

                return response;
            }
        }
Esempio n. 2
0
        public bool FileExists(DateTime date)
        {
            OrderRepository repo = new OrderRepository();

            return repo.FileExists(date);
        }