protected LinkModel GetLastLink() { if (_pagedResponseModel.Total <= _pagedRequestModel.Take) { return(null); } var skipToNext = _pagedRequestModel.Skip + _pagedRequestModel.Take; if (skipToNext >= _pagedResponseModel.Total) { return(null); } var skipToLast = (int)(Math.Ceiling((_pagedResponseModel.Total - (double)_pagedRequestModel.Take) / _pagedRequestModel.Take) * _pagedRequestModel.Take); var pagedRequestModel = _pagedRequestModel.Clone(); pagedRequestModel.Skip = skipToLast; var routeValueDictionary = new RouteValueDictionary(pagedRequestModel); var link = new LinkModel { Method = _method, Url = GetUrlWithQueries(_endpoint, routeValueDictionary), Data = routeValueDictionary }; return(link); }
protected LinkModel GetNextLink() { var skipToNext = _pagedRequestModel.Skip + _pagedRequestModel.Take; if (skipToNext >= _pagedResponseModel.Total) { return(null); } var pagedRequestModel = _pagedRequestModel.Clone(); pagedRequestModel.Skip = skipToNext; var routeValueDictionary = new RouteValueDictionary(pagedRequestModel); var link = new LinkModel { Method = _method, Url = GetUrlWithQueries(_endpoint, routeValueDictionary), Data = routeValueDictionary }; return(link); }
protected LinkModel GetPreviousLink() { if (_pagedRequestModel.Skip == 0 || _pagedResponseModel.Total <= _pagedRequestModel.Skip) { return(null); } var skipToPrevious = Math.Max(_pagedRequestModel.Skip - _pagedRequestModel.Take, 0); if (skipToPrevious <= 0) { return(GetFirstLink()); } var pagedRequestModel = _pagedRequestModel.Clone(); pagedRequestModel.Skip = skipToPrevious; var routeValueDictionary = new RouteValueDictionary(pagedRequestModel); var link = new LinkModel { Method = _method, Url = GetUrlWithQueries(_endpoint, routeValueDictionary), Data = routeValueDictionary }; return(link); }
protected LinkModel GetMetaLink() { var routeValueDictionary = new RouteValueDictionary(_pagedRequestModel); var link = new LinkModel { Method = _method, Url = GetUrlWithQueries(_endpoint, routeValueDictionary), Data = routeValueDictionary }; return(link); }
protected LinkModel GetFirstLink() { var pagedRequestModel = _pagedRequestModel.Clone(); pagedRequestModel.Skip = 0; var routeValueDictionary = new RouteValueDictionary(pagedRequestModel); var link = new LinkModel { Method = _method, Url = GetUrlWithQueries(_endpoint, routeValueDictionary), Data = routeValueDictionary }; return(link); }
public PagedMetaModel(IUrlHelper urlHelper, TRequest pagedRequestModel, PagedResponseModel <TResponse> pagedResponseModel, HttpMethod method = HttpMethod.GET) : this(pagedResponseModel) { _pagedRequestModel = pagedRequestModel; _method = method; _endpoint = urlHelper.ActionContext.HttpContext.Request.Path.Value; _endpoint = urlHelper.AbsoluteContent(_endpoint); Meta = GetMetaLink(); First = GetFirstLink(); Previous = GetPreviousLink(); Next = GetNextLink(); Last = GetLastLink(); }