public virtual void GenerateLinks( PagingStringResources stringResources, ActionInfo actionInfo) { const int FirstPageNumber = 1; int totalPages = this.TotalPages ?? 0; this.Links = new List <LinkDto>(); this.AddLink(FirstPageNumber, stringResources.FirstPage, actionInfo); if (this.PageNumber > FirstPageNumber && this.PageNumber <= totalPages) { this.AddLink(this.PageNumber - 1, stringResources.PreviousPage, actionInfo); } if (this.PageNumber >= FirstPageNumber && this.PageNumber <= totalPages) { this.AddLink(this.PageNumber, stringResources.CurrentPage, actionInfo); } if (this.PageNumber >= FirstPageNumber - 1 && this.PageNumber < totalPages) { this.AddLink(this.PageNumber + 1, stringResources.NextPage, actionInfo); } if (totalPages > 0) { this.AddLink(totalPages, stringResources.LastPage, actionInfo); } }
public ShowsController( IShowsService showsService, IPageParametersValidator pageParametersValidator, IMapper mapper, PagingStringResources pageStringResources, IUrlHelper urlHelper) { this.showsService = showsService ?? throw new ArgumentNullException(nameof(showsService)); this.pageParametersValidator = pageParametersValidator ?? throw new ArgumentNullException(nameof(pageParametersValidator)); this.mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); this.pageStringResources = pageStringResources ?? throw new ArgumentNullException(nameof(pageStringResources)); this.urlHelper = urlHelper ?? throw new ArgumentNullException(nameof(urlHelper)); }
private static PageHateoasResponse ProcessPagingValidationException(PagingValidationException pagingValidationException, ExceptionContext context, PagingStringResources pageStringResources, IUrlHelper urlHelper) { const int DefaultPageNumber = 1; const int DefaultPageSize = 25; var errorResponse = new PageHateoasResponse { Errors = pagingValidationException.ValidationMessages, PageNumber = DefaultPageNumber, PageSize = DefaultPageSize }; var actionInfo = new ActionInfo { UrlHelper = urlHelper, RouteName = context.ActionDescriptor.AttributeRouteInfo.Name, HttpMethod = context.HttpContext.Request.Method }; errorResponse.GenerateLinks(pageStringResources, actionInfo); return(errorResponse); }