Example #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();
            }
        }
Example #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();
            }
        }
Example #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();
     }
 }
Example #4
0
        public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
        {
            var result = context.Result as ObjectResult;

            if (FiltersHelper.IsResponseSuccesful(result))
            {
                TDto dto = result.Value as TDto;
                if (filterConfiguration.SupportsCustomDataType && FiltersHelper.GetValueFromHeader(context, "Accept").Equals(filterConfiguration.CustomDataType))
                {
                    var dtoWithLinks = HateoasHelper.CreateLinksForSingleResource(dto, filterConfiguration, linkGenerator, context.Controller.GetType());
                    var envelopDto   = new EnvelopDto <TDto>(
                        dto,
                        dtoWithLinks.Links);
                    result.Value = envelopDto;
                }
                else
                {
                    result.Value = dto;
                }
            }
            await next();
        }