Example #1
0
        public async Task <PackedList <TResult> > SelectPageAsync <TResult>(int page, int pageSize) where TResult : new()
        {
            var entries = await _repository.SelectAsync(_expression, _orderBy, _includes, page, pageSize);

            var result = new PackedList <TResult>
            {
                Data = entries.Select(x => new TResult().InjectFrom <CloneInjection>(x)).Cast <TResult>()
            };

            return(result);
        }
Example #2
0
        public virtual async Task <PackedList <TViewModel> > SelectAsync <TViewModel>(Expression <Func <TEntity, bool> > predicate,
                                                                                      Func <IQueryable <TEntity>, IOrderedQueryable <TEntity> > orderBy, Expression <Func <TEntity, object> > includeProperties,
                                                                                      int?pageIndex, int?pageSize)
            where TViewModel : new()
        {
            var query = await Query(predicate).Include(includeProperties).OrderBy(orderBy).SelectPageAsync(pageIndex ?? 0, pageSize ?? 0);

            var result = new PackedList <TViewModel>
            {
                Data  = query.Select(x => new TViewModel().InjectFrom(x)).Cast <TViewModel>(),
                Total = TotalCount()
            };

            return(result);
        }
Example #3
0
        public async static Task <PackedList <TResult> > PaginateProjection <TEntity, TResult>
            (this IQueryable <TEntity> query, CommonFilters filters, MapperConfiguration mapperConfiguration)
            where TEntity : AuditableEntity where TResult : class
        {
            PackedList <TResult> packedResult = new PackedList <TResult>();

            if (filters.Page.HasValue && filters.PageSize.HasValue)
            {
                var skip = (filters.Page.Value - 1) * filters.PageSize.Value;
                packedResult.Total = await query.ProjectTo <TResult>(mapperConfiguration).CountAsync();

                packedResult.Data = await query.Skip(skip).Take(filters.PageSize.Value)
                                    .ProjectTo <TResult>(mapperConfiguration).ToListAsync();
            }
            else
            {
                packedResult.Data = await query.ProjectTo <TResult>(mapperConfiguration).ToListAsync();

                packedResult.Total = packedResult.Data.Count();
            }

            return(packedResult);
        }