private static List <IUserAuth> SortAndPage(IFindFluent <UserAuth, UserAuth> q, string orderBy, int?skip, int?take) { if (!string.IsNullOrEmpty(orderBy)) { orderBy = AuthRepositoryUtils.ParseOrderBy(orderBy, out var desc); q = q.Sort(desc ? Builders <UserAuth> .Sort.Descending(orderBy) : Builders <UserAuth> .Sort.Ascending(orderBy)); } if (skip != null) { q = q.Skip(skip.Value); } if (take != null) { q = q.Limit(take.Value); } return(q.ToList().ConvertAll(x => x as IUserAuth)); }
private static async Task <List <IUserAuth> > SortAndPageAsync(IFindFluent <UserAuth, UserAuth> q, string orderBy, int?skip, int?take, CancellationToken token = default) { if (!string.IsNullOrEmpty(orderBy)) { orderBy = AuthRepositoryUtils.ParseOrderBy(orderBy, out var desc); q = q.Sort(desc ? Builders <UserAuth> .Sort.Descending(orderBy) : Builders <UserAuth> .Sort.Ascending(orderBy)); } if (skip != null) { q = q.Skip(skip.Value); } if (take != null) { q = q.Limit(take.Value); } return((await q.ToListAsync(token).ConfigAwait()).ConvertAll(x => x as IUserAuth)); }
static IQueryable <TUserAuth> SortAndPage(IRavenQueryable <TUserAuth> q, string orderBy, int?skip, int?take) { var qEnum = q.AsQueryable(); if (!string.IsNullOrEmpty(orderBy)) { orderBy = AuthRepositoryUtils.ParseOrderBy(orderBy, out var desc); qEnum = desc ? q.OrderByDescending(orderBy) : q.OrderBy(orderBy); } if (skip != null) { qEnum = qEnum.Skip(skip.Value); } if (take != null) { qEnum = qEnum.Take(take.Value); } return(qEnum); }