Example #1
0
        public IHttpActionResult FinalizeResponse <T1>(IDataResponse <List <T1> > response, string routeName, IPageable search, string fields = null, UrlHelper urlHelper = null)
            where T1 : class
        {
            try
            {
                urlHelper = urlHelper ?? GetUrlHelper();
                if (!response.IsSuccessful)
                {
                    return(BadRequest(string.Join(", ", response.ErrorMessages)));
                }

                var totalCount = response.TotalResults;

                Pagination.AddPaginationHeaderToResponse(urlHelper, search, totalCount, routeName);
                var dynamicResponse = DynamicTransmogrifier.ToDynamicResponse(response, fields);
                if (!dynamicResponse.IsSuccessful)
                {
                    throw new Exception(string.Join(", ", dynamicResponse.ErrorMessages));
                }
                return(Ok(dynamicResponse));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex);
                return(InternalServerError(new Exception(ex.Message)));
            }
        }