Exemple #1
0
        public async Task <IActionResult> Get([FromQuery] SimplePagedRequest request)
        {
            var result = await userRepository
                         .GetPagedListAsync(request);

            return(Ok(result));
        }
Exemple #2
0
        public static async Task <PagedResult <TDocument> > ToPagedResult <TDocument>(
            this IMongoCollection <TDocument> collection,
            FilterDefinition <TDocument> filter,
            SimplePagedRequest request,
            SortDefinition <TDocument> sort = null) where TDocument : DocumentBase
        {
            if (sort == null)
            {
                sort = Builders <TDocument> .Sort.Descending(x => x.Id);
            }

            if (filter == null)
            {
                filter = Builders <TDocument> .Filter.Empty;
            }

            var result = collection
                         .Find(filter)
                         .Sort(sort)
                         .Limit(request.PageSize)
                         .Skip(request.PageIndex * request.PageSize)
                         .ToListAsync();

            var count = collection
                        .Find(filter)
                        .CountAsync();

            await Task.WhenAll(result, count);

            return(new PagedResult <TDocument>(request.PageIndex, request.PageSize, result.Result, count.Result));
        }
        public static async Task <IPagedResult <TDocument> > ToPagedResultAsync <TDocument, TKey>(
            this IMongoCollection <TDocument> collection,
            FilterDefinition <TDocument> filter,
            SimplePagedRequest request,
            SortDefinition <TDocument> sort     = null,
            CancellationToken cancellationToken = default(CancellationToken)) where TDocument : DocumentBase <TKey>
        {
            if (sort == null)
            {
                sort = Builders <TDocument> .Sort.Descending(x => x.Id);
            }

            if (filter == null)
            {
                filter = Builders <TDocument> .Filter.Empty;
            }

            var result = collection
                         .Find(filter)
                         .Sort(sort)
                         .Limit(request.PageSize)
                         .Skip(request.PageIndex * request.PageSize)
                         .ToListAsync(cancellationToken);

            var count = collection
                        .Find(filter)
                        .CountDocumentsAsync(cancellationToken);

            await Task.WhenAll(result, count).ConfigureAwait(false);

            return(new PagedResult <TDocument>(request.PageIndex, request.PageSize, result.Result, count.Result));
        }
        public virtual Task <IPagedResult <T> > GetPagedListAsync(SimplePagedRequest request, FilterDefinition <T> filters = null, SortDefinition <T> sort = null, CancellationToken cancellation = default)
        {
            if (filters == null)
            {
                filters = Builders <T> .Filter.Empty;
            }

            return(Collection.ToPagedResultAsync <T, TK>(filters, request, sort, cancellation));
        }
Exemple #5
0
 public static Task <IPagedResult <TDocument> > ToPagedResultAsync <TDocument, TKey>(
     this IMongoCollection <TDocument> collection,
     FilterDefinition <TDocument> filter,
     SimplePagedRequest request,
     SortDefinition <TDocument> sort     = null,
     CancellationToken cancellationToken = default)
     where TDocument : DocumentBase <TKey>
 {
     return(collection.ToPagedResultAsync <TDocument, TKey, TDocument>(filter, request, (TDocument item) => item, sort, cancellationToken));
 }
Exemple #6
0
        public static async Task <IPagedResult <TResult> > ToPagedResultAsync <TDocument, TKey, TResult>(
            this IMongoCollection <TDocument> collection,
            FilterDefinition <TDocument> filter,
            SimplePagedRequest request,
            Func <TDocument, TResult> transform,
            SortDefinition <TDocument> sort     = null,
            CancellationToken cancellationToken = default)
            where TDocument : DocumentBase <TKey>
        {
            if (filter == null)
            {
                filter = Builders <TDocument> .Filter.Empty;
            }

            var query = collection
                        .Find(filter);

            if (sort != null)
            {
                query.Sort(sort);
            }

            var result = query
                         .Paged(request)
                         .ToListAsync(cancellationToken);

            var count = collection
                        .Find(filter)
                        .CountDocumentsAsync(cancellationToken);

            await Task.WhenAll(result, count);

            var methodResult = new TResult[result.Result.Count];

            for (var i = 0; i < result.Result.Count; i++)
            {
                methodResult[i] = transform(result.Result[i]);
            }

            return(new PagedResult <TResult>(request.PageIndex, request.PageSize, methodResult, count.Result));
        }
Exemple #7
0
 public static IFindFluent <TDocument, TDocument> Page <TDocument>(this IFindFluent <TDocument, TDocument> find, SimplePagedRequest request)
 {
     return(find
            .Limit(request.PageSize)
            .Skip(request.PageIndex * request.PageSize));
 }
Exemple #8
0
 public static Task <IPagedResult <TR> > GetPagedListAsync <T, TK, TR>(this IMongoCollection <T> instance, SimplePagedRequest request, FilterDefinition <T> filters, Func <T, TR> transform, SortDefinition <T> sort = null, CancellationToken cancellation = default)
     where T : DocumentBase <TK>
 {
     return(instance.ToPagedResultAsync <T, TK, TR>(filters, request, transform, sort, cancellationToken: cancellation));
 }
Exemple #9
0
 public Task <PagedResult <Movie> > GetMovies(SimplePagedRequest request)
 {
     return(this.movieRepository
            .Collection
            .ToPagedResult(Builders <Movie> .Filter.Empty, request));
 }