public PagedDataResult <T> GetByIdsPaged <T>(IEnumerable <long> ids, IPagedDataRequest request) where T : Entity { if (request.PageSize <= 0) { var items = this.GetByIds <T>(ids); // return new PagedDataResult<T>(items, new PageData(0, items.Count(), 1, items.Count(), false)); return(new PagedDataResult <T>(items, PageData.GetUnpagedData(items.Count()))); } else { // get the details... var pages = Runtime.Current.GetPages(ids, request.PageSize); IEnumerable <T> items = null; if (request.PageNumber < pages.Count) { items = (IEnumerable <T>) this.EntityType.Persistence.GetByIds <T>(pages[request.PageNumber]); } else { items = this.EntityType.CreateCollectionInstance <T>(); } // setup... var data = new PageData(request.PageNumber, request.PageSize, pages.Count, ids.Count(), false); return(new PagedDataResult <T>(items, data)); } }
private static PagedDataResult <T> GetPageInternal <T>(this IEnumerable <T> items, IPagedDataRequest request) { if (request.PageSize > 0) { var pages = items.SplitIntoPages(request.PageSize); if (request.PageNumber < pages.Count) { return(new PagedDataResult <T>(pages[request.PageNumber], new PageData(request.PageNumber, request.PageSize, pages.Count, items.Count(), false))); } else { return(new PagedDataResult <T>(new List <T>(), new PageData(request.PageNumber, request.PageSize, pages.Count, items.Count(), false))); } } else { return(new PagedDataResult <T>(items, PageData.GetUnpagedData(items.Count()))); } }