public HttpResponseMessage InitializeOrder(HttpRequestMessage request, [FromBody] OrderDTO orderDTO)
        {
            OrdersApiModel ordersWebApiModel = new OrdersApiModel();
            TransactionalInformation transaction = new TransactionalInformation();
            OrdersBusinessService ordersBusinessService;
            CustomersBusinessService customersBusinessService;
            ordersWebApiModel.IsAuthenicated = true;

            customersBusinessService = new CustomersBusinessService(customersDataService);
            Customer customer = customersBusinessService.GetCustomer(orderDTO.CustomerID, out transaction);
            if (transaction.ReturnStatus == false)
            {
                ordersWebApiModel.ReturnMessage = transaction.ReturnMessage;
                ordersWebApiModel.ReturnStatus = transaction.ReturnStatus;
                ordersWebApiModel.ValidationErrors = transaction.ValidationErrors;
                var badResponse = Request.CreateResponse<OrdersApiModel>(HttpStatusCode.BadRequest, ordersWebApiModel);
                return badResponse;
            }

            ordersBusinessService = new OrdersBusinessService(ordersDataService);
            List<Shipper> shippers = ordersBusinessService.GetShippers(out transaction);
            if (transaction.ReturnStatus == false)
            {
                ordersWebApiModel.ReturnMessage = transaction.ReturnMessage;
                ordersWebApiModel.ReturnStatus = transaction.ReturnStatus;
                ordersWebApiModel.ValidationErrors = transaction.ValidationErrors;
                var badResponse = Request.CreateResponse<OrdersApiModel>(HttpStatusCode.BadRequest, ordersWebApiModel);
                return badResponse;
            }
            
            ordersWebApiModel.ReturnStatus = transaction.ReturnStatus;
            ordersWebApiModel.ReturnMessage = transaction.ReturnMessage;
            ordersWebApiModel.Customer = customer;
            ordersWebApiModel.Shippers = shippers;

            var response = Request.CreateResponse<OrdersApiModel>(HttpStatusCode.OK, ordersWebApiModel);
            return response;


        }
        public HttpResponseMessage DeleteOrderLineItem(HttpRequestMessage request, [FromBody] OrderDetailDTO orderDTO)
        {
            OrdersApiModel ordersWebApiModel = new OrdersApiModel();
            TransactionalInformation transaction = new TransactionalInformation();
            OrdersBusinessService ordersBusinessService;
            ordersWebApiModel.IsAuthenicated = true;

            ordersBusinessService = new OrdersBusinessService(ordersDataService);

            ordersBusinessService.DeleteOrderDetailLineItem(              
                orderDTO.OrderDetailID,               
                out transaction);

            if (transaction.ReturnStatus == false)
            {
                ordersWebApiModel.ReturnMessage = transaction.ReturnMessage;
                ordersWebApiModel.ReturnStatus = transaction.ReturnStatus;
                ordersWebApiModel.ValidationErrors = transaction.ValidationErrors;
                var badResponse = Request.CreateResponse<OrdersApiModel>(HttpStatusCode.BadRequest, ordersWebApiModel);
                return badResponse;
            }

            Order order = ordersBusinessService.GetOrder(orderDTO.OrderID, out transaction);
            if (transaction.ReturnStatus == false)
            {
                ordersWebApiModel.ReturnMessage = transaction.ReturnMessage;
                ordersWebApiModel.ReturnStatus = transaction.ReturnStatus;
                ordersWebApiModel.ValidationErrors = transaction.ValidationErrors;
                var badResponse = Request.CreateResponse<OrdersApiModel>(HttpStatusCode.BadRequest, ordersWebApiModel);
                return badResponse;
            }

            List<OrderDetails> orderDetails = ordersBusinessService.GetOrderDetails(orderDTO.OrderID, out transaction);
            if (transaction.ReturnStatus == false)
            {
                ordersWebApiModel.ReturnMessage = transaction.ReturnMessage;
                ordersWebApiModel.ReturnStatus = transaction.ReturnStatus;
                ordersWebApiModel.ValidationErrors = transaction.ValidationErrors;
                var badResponse = Request.CreateResponse<OrdersApiModel>(HttpStatusCode.BadRequest, ordersWebApiModel);
                return badResponse;
            }

            transaction.ReturnMessage.Add("Detail line item successfully deleted.");
            
            ordersWebApiModel.ReturnStatus = transaction.ReturnStatus;
            ordersWebApiModel.ReturnMessage = transaction.ReturnMessage;
            ordersWebApiModel.Order = order;
            ordersWebApiModel.OrderDetails = orderDetails;

            var response = Request.CreateResponse<OrdersApiModel>(HttpStatusCode.OK, ordersWebApiModel);
            return response;

        }
        public HttpResponseMessage UpdateOrder(HttpRequestMessage request, [FromBody] OrderDTO orderDTO)
        {
            OrdersApiModel ordersWebApiModel = new OrdersApiModel();
            TransactionalInformation transaction = new TransactionalInformation();
            OrdersBusinessService ordersBusinessService;
            ordersWebApiModel.IsAuthenicated = true;

            if (orderDTO.ShipAddress == null) orderDTO.ShipAddress = string.Empty;
            if (orderDTO.ShipCity == null) orderDTO.ShipCity = string.Empty;
            if (orderDTO.ShipRegion == null) orderDTO.ShipRegion = string.Empty;
            if (orderDTO.ShipPostalCode == null) orderDTO.ShipPostalCode = string.Empty;
            if (orderDTO.ShipCountry == null) orderDTO.ShipCountry = string.Empty;

            ordersBusinessService = new OrdersBusinessService(ordersDataService);

            Order order = ordersBusinessService.UpdateOrder(
                orderDTO.OrderID,
                orderDTO.RequiredDate,
                orderDTO.ShipName,
                orderDTO.ShipAddress,
                orderDTO.ShipCity,
                orderDTO.ShipRegion,
                orderDTO.ShipPostalCode,
                orderDTO.ShipCountry,
                orderDTO.ShipperID,
                out transaction);

            if (transaction.ReturnStatus == false)
            {
                ordersWebApiModel.ReturnMessage = transaction.ReturnMessage;
                ordersWebApiModel.ReturnStatus = transaction.ReturnStatus;
                ordersWebApiModel.ValidationErrors = transaction.ValidationErrors;
                var badResponse = Request.CreateResponse<OrdersApiModel>(HttpStatusCode.BadRequest, ordersWebApiModel);
                return badResponse;
            }
            
            ordersWebApiModel.ReturnStatus = transaction.ReturnStatus;
            ordersWebApiModel.ReturnMessage = transaction.ReturnMessage;
            ordersWebApiModel.Order = order;

            var response = Request.CreateResponse<OrdersApiModel>(HttpStatusCode.OK, ordersWebApiModel);
            return response;

        }
        public HttpResponseMessage OrderInquiry([FromBody] OrderInquiryDTO orderInquiryDTO)
        {

            if (orderInquiryDTO.CustomerCode == null) orderInquiryDTO.CustomerCode = string.Empty;
            if (orderInquiryDTO.CompanyName == null) orderInquiryDTO.CompanyName = string.Empty;
            if (orderInquiryDTO.SortDirection == null) orderInquiryDTO.SortDirection = string.Empty;
            if (orderInquiryDTO.SortExpression == null) orderInquiryDTO.SortExpression = string.Empty;

            OrdersApiModel ordersWebApiModel = new OrdersApiModel();
            TransactionalInformation transaction = new TransactionalInformation();
            OrdersBusinessService ordersBusinessService;

            ordersWebApiModel.IsAuthenicated = true;

            DataGridPagingInformation paging = new DataGridPagingInformation();
            paging.CurrentPageNumber = orderInquiryDTO.CurrentPageNumber;
            paging.PageSize = orderInquiryDTO.PageSize;
            paging.SortExpression = orderInquiryDTO.SortExpression;
            paging.SortDirection = orderInquiryDTO.SortDirection;

            if (paging.SortDirection == "") paging.SortDirection = "DESC";
            if (paging.SortExpression == "") paging.SortExpression = "OrderDate";

            ordersBusinessService = new OrdersBusinessService(ordersDataService);

            List<OrderInquiry> orders = ordersBusinessService.OrderInquiry(orderInquiryDTO.CustomerCode, orderInquiryDTO.CompanyName, paging, out transaction);

            ordersWebApiModel.Orders = orders;           
            ordersWebApiModel.ReturnStatus = transaction.ReturnStatus;
            ordersWebApiModel.ReturnMessage = transaction.ReturnMessage;
            ordersWebApiModel.TotalPages = transaction.TotalPages;
            ordersWebApiModel.TotalRows = transaction.TotalRows;
            ordersWebApiModel.PageSize = paging.PageSize;

            if (transaction.ReturnStatus == true)
            {
                var response = Request.CreateResponse<OrdersApiModel>(HttpStatusCode.OK, ordersWebApiModel);
                return response;
            }

            var badResponse = Request.CreateResponse<OrdersApiModel>(HttpStatusCode.BadRequest, ordersWebApiModel);
            return badResponse;


        }