public PagedQueryResponse(Tquery query, ReadOnlyCollection <Telement> collection, ReadOnlyCollection <OrderByApplication <TorderBy> > orderedBy, PagingRequest paging, int totalCount) { // Why would you pass nulls? What the hell is wrong with you? if (query == null) { throw new ArgumentNullException("query"); } if (collection == null) { throw new ArgumentNullException("collection"); } if (orderedBy == null) { throw new ArgumentNullException("orderedBy"); } // We got a collection of records BIGGER than the page size? WtF? if (collection.Count > paging.PageSize) { throw new ArgumentOutOfRangeException("collection", "Page collection is too big for page size"); } // Set our known properties: this.Query = query; this.Collection = collection; this.OrderedBy = orderedBy; this.Paging = paging; this.TotalCount = totalCount; // Calculate the remaining properties: this.PageCount = totalCount / paging.PageSize + ((totalCount % paging.PageSize) > 0 ? 1 : 0); this.IsFirstPage = paging.PageNumber == 1; // If PageCount == 0 we're still on the last page: this.IsLastPage = paging.PageNumber == Math.Max(1, this.PageCount); }
public async Task<PagedQueryResponse<TagQuery, Tag, TagOrderBy>> SearchTags(TagQuery query, ReadOnlyCollection<OrderByApplication<TagOrderBy>> orderBy, PagingRequest paging) { // Filter the results: List<Tag> tags = await searchTags(query); // Order the results: IEnumerable<Tag> ordered = orderResults(tags, orderBy); tags = ordered.ToList(tags.Count); // Page the results: List<Tag> page = tags.Skip(paging.PageIndex * paging.PageSize).Take(paging.PageSize).ToList(paging.PageSize); return new PagedQueryResponse<TagQuery, Tag, TagOrderBy>(query, new ReadOnlyCollection<Tag>(page), orderBy, paging, tags.Count); }