예제 #1
0
        public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
        {
            var result = context.Result as ObjectResult;

            if (FiltersHelper.IsResponseSuccesful(result))
            {
                PaginationModel <TEntity> paginationModel =
                    await FiltersHelper.GetParameterFromActionAsync <PaginationModel <TEntity> >(context);

                IQueryable <TDto> list = result.Value as IQueryable <TDto>;
                var dtoPagedList       = await list.ToPagedListAsync(paginationModel.PageSize, paginationModel.PageNumber);

                /// Doesn't support many pagination methods for a single controller
                var                paginationMethodInfo = filterConfiguration.ControllerInfoDictionary[context.Controller.GetType()].ControllerActions.Where(t => t.ResourceType == Attributes.ResourceType.Collection).FirstOrDefault();
                string             mediaType            = FiltersHelper.GetValueFromHeader(context, "Accept");
                PaginationMetadata paginationMetadata   = paginationHelperService.GeneratePaginationMetaData(dtoPagedList, paginationModel, context.Controller.GetType().Name, paginationMethodInfo.ActionName);
                if (filterConfiguration.SupportsCustomDataType && mediaType.Equals(filterConfiguration.CustomDataType, StringComparison.CurrentCultureIgnoreCase))
                {
                    var controllerType = context.Controller.GetType();
                    var dtoPagedListWithExternalLinks = HateoasHelper.CreateLinksForCollectionResource(dtoPagedList, filterConfiguration, paginationMetadata, context.Controller.GetType());
                    var shapedDtoPagedListWithLinks   = new EnvelopCollection <EnvelopDto <TDto> > {
                        Values = dtoPagedListWithExternalLinks.Values.Select(dto => {
                            return(HateoasHelper
                                   .CreateLinksForSingleResource(dto, filterConfiguration, linkGenerator, controllerType));
                        }), Links = dtoPagedListWithExternalLinks.Links
                    };
                    result.Value = shapedDtoPagedListWithLinks;
                }
                else
                {
                    result.Value = dtoPagedList;
                }
                await next();
            }
        }
예제 #2
0
        public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
        {
            PaginatedResult result = context.Result as PaginatedResult;

            if (FiltersHelper.IsResponseSuccesful(result))
            {
                PaginationModel paginationModel = await FiltersHelper.GetParameterKnowingBaseTypeFromActionAsync <PaginationModel>(context);

                var paginationMethodInfo = filterConfiguration.ControllerInfoDictionary[context.Controller.GetType()].ControllerActions.
                                           Where(t => t.ResourceType == Attributes.ResourceType.Collection).FirstOrDefault();
                PaginationMetadata paginationMetadata = paginationHelperService.GeneratePaginationMetaData(
                    result.PaginationInfo, paginationModel, FiltersHelper.GetControllerName(context), paginationMethodInfo.ActionName);
                string             mediaType = FiltersHelper.GetValueFromHeader(context, "Accept");
                IEnumerable <TDto> pagedList = (IEnumerable <TDto>)result.Value;
                if (filterConfiguration.HateoasConfiguration.SupportsCustomDataType && mediaType.Equals(filterConfiguration.HateoasConfiguration.CustomDataType, StringComparison.CurrentCultureIgnoreCase))
                {
                    EnvelopCollection <EnvelopDto <TDto> > pagedListWithLinks = AddInternalAndExternalLinks(context, paginationMetadata, pagedList);
                    result.Value = pagedListWithLinks;
                }
                else
                {
                    result.Value = pagedList;
                }
                await next();
            }
        }
예제 #3
0
 public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) {
     var result = context.Result as ObjectResult;
     if (FiltersHelper.IsResponseSuccesful(result)) {
         PaginationModel<TEntity> paginationModel = await FiltersHelper.GetParameterFromActionAsync<PaginationModel<TEntity>>(context);
         string controllerName = context.Controller.GetType().Name;
         IQueryable<TEntity> list = result.Value as IQueryable<TEntity>;
         var pagedList = await list.ToPagedListAsync(paginationModel.PageSize, paginationModel.PageNumber);
         var paginationMetadata = paginationHelperService.GeneratePaginationMetaData(pagedList, paginationModel, controllerName, "");
         HateoasHelper.AddPaginationHeaders(filterConfiguration, context, paginationMetadata);
         await next();
     }
 }