예제 #1
0
        internal static void AddPaginationHeaders(HateoasScanner filterConfiguration, ResultExecutingContext context, PaginationMetadata paginationMetadata)
        {
            string pagination = (filterConfiguration.SupportsCustomDataType &&
                                 context.HttpContext.Request.Headers["Accept"].Equals(filterConfiguration.CustomDataType))
                                ? JsonConvert.SerializeObject(paginationMetadata)
                                : JsonConvert.SerializeObject(paginationMetadata.ToPaginationInfo());

            context.HttpContext.Response.Headers.Add("X-Pagination", pagination);
        }
예제 #2
0
        internal static EnvelopCollection <TDto> CreateLinksForCollectionResource <TDto>(IEnumerable <TDto> dtoCollection, HateoasScanner filterConfiguration, PaginationMetadata paginationMetadata, Type controllerType)
            where TDto : IIdentityDto
        {
            var action  = filterConfiguration.ControllerInfoDictionary[controllerType].ControllerActions.First(t => t.ResourceType == ResourceType.Collection);
            var envelop = new EnvelopCollection <TDto>(dtoCollection);

            envelop.Links.Add(new LinkDto(paginationMetadata.NextPageLink, $"{action.MethodName}-next", action.MethodType));
            envelop.Links.Add(new LinkDto(paginationMetadata.PreviousPageLink, $"{action.MethodName}-previous", action.MethodType));
            envelop.Links.Add(new LinkDto(paginationMetadata.SelfPageLink, $"{action.MethodName}", action.MethodType));
            return(envelop);
        }