コード例 #1
0
        public HttpResponseMessage GetCustomers(HttpRequestMessage request, [FromBody] CustomerInformation customerInformation)
        {
            TransactionalInformation transaction = new TransactionalInformation();

            string customerCode      = customerInformation.CustomerCode;
            string companyName       = customerInformation.CompanyName;
            int    currentPageNumber = customerInformation.CurrentPageNumber;
            int    pageSize          = customerInformation.PageSize;
            string sortExpression    = customerInformation.SortExpression;
            string sortDirection     = customerInformation.SortDirection;

            int totalRows = 0;

            CustomerBusinessService customerBusinessService = new CustomerBusinessService(_customerDataService);
            List <Customer>         customers = customerBusinessService.GetCustomers(customerCode, companyName, currentPageNumber, pageSize, sortDirection, sortExpression, out totalRows, out transaction);

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

            customerInformation = new CustomerInformation();
            customerInformation.ReturnStatus = transaction.ReturnStatus;
            customerInformation.TotalRows    = totalRows;
            customerInformation.TotalPages   = Utilities.CalculateTotalPages(totalRows, pageSize);
            customerInformation.ReturnMessage.Add("page " + currentPageNumber + " of " + customerInformation.TotalPages + " returned at " + DateTime.Now.ToString());
            customerInformation.Customers = customers;

            var response = Request.CreateResponse <CustomerInformation>(HttpStatusCode.OK, customerInformation);

            return(response);
        }
コード例 #2
0
        public HttpResponseMessage GetCustomers(HttpRequestMessage request, [FromBody] CustomerViewModel customerViewModel)
        {
            TransactionalInformation transaction;

            int    currentPageNumber = customerViewModel.CurrentPageNumber;
            int    pageSize          = customerViewModel.PageSize;
            string sortExpression    = customerViewModel.SortExpression;
            string sortDirection     = customerViewModel.SortDirection;

            CustomerBusinessService customerBusinessService = new CustomerBusinessService(_customerDataService);
            List <Customer>         customers = customerBusinessService.GetCustomers(currentPageNumber, pageSize, sortExpression, sortDirection, out transaction);

            if (transaction.ReturnStatus == false)
            {
                customerViewModel.ReturnStatus     = false;
                customerViewModel.ReturnMessage    = transaction.ReturnMessage;
                customerViewModel.ValidationErrors = transaction.ValidationErrors;

                var responseError = Request.CreateResponse <CustomerViewModel>(HttpStatusCode.BadRequest, customerViewModel);
                return(responseError);
            }

            customerViewModel.TotalPages    = transaction.TotalPages;
            customerViewModel.TotalRows     = transaction.TotalRows;
            customerViewModel.Customers     = customers;
            customerViewModel.ReturnStatus  = true;
            customerViewModel.ReturnMessage = transaction.ReturnMessage;

            var response = Request.CreateResponse <CustomerViewModel>(HttpStatusCode.OK, customerViewModel);

            return(response);
        }