Exemplo n.º 1
0
        public virtual PagingResult <TEntity> FindAllWithPaging(Expression <Func <TEntity, bool> > predicate, int skip, int numberofRecords)
        {
            var querydb = Collection.AsQueryable().Where(predicate);

            PagingResult <TEntity> currentPageResult = new PagingResult <TEntity>();

            currentPageResult.TotalCount             = querydb.Count();
            currentPageResult.CurrentPage            = skip;
            currentPageResult.NumberofRecordsPerPage = numberofRecords;

            currentPageResult.CurrentData = querydb.Skip(skip * numberofRecords).Take(numberofRecords).ToList();

            return(currentPageResult);
        }
Exemplo n.º 2
0
        public virtual async Task <PagingResult <TEntity> > FindAllWithPagingAsync(Expression <Func <TEntity, bool> > predicate, int skip, int numberofRecords)
        {
            var querydb = Collection.Find(predicate);

            PagingResult <TEntity> currentPageResult = new PagingResult <TEntity>();

            var totalCount = querydb.CountDocumentsAsync();

            currentPageResult.CurrentPage            = skip;
            currentPageResult.NumberofRecordsPerPage = numberofRecords;

            var currentData = querydb.Skip(skip * numberofRecords).Limit(numberofRecords).ToListAsync();

            await Task.WhenAll(totalCount, currentData);  /**Important show how to wait for all async actions to finish **/

            currentPageResult.CurrentData = currentData.Result;
            currentPageResult.TotalCount  = (int)totalCount.Result;

            return(currentPageResult);
        }