Пример #1
0
            public virtual async Task <IQueryable <T> > Obter(Expression <Func <T, bool> > filtro = null,
                                                              PaginacaoDTO paginacao = null,
                                                              params Expression <Func <T, object> >[] includes)
            {
                var query = _dbSet.AsQueryable();

                if (filtro != null)
                {
                    query = _dbSet.AsQueryable().Where(filtro);
                }

                if (includes != null)
                {
                    foreach (var includeProperty in includes)
                    {
                        query = query.Include(includeProperty);
                    }
                }

                if (paginacao != null)
                {
                    query = _dbSet.AsQueryable().Skip((paginacao.PageNumber.Value - 1)
                                                      * paginacao.PageSize.Value).Take(paginacao.PageSize.Value);
                }
                return(query.AsNoTracking());
            }
Пример #2
0
        public async Task <ActionResult <List <Pessoa> > > Get([FromQuery] PaginacaoDTO paginacao)
        {
            var queryable = _db.Pessoa.AsQueryable();

            await HttpContext.InserirParamentroPaginacaoResposta(queryable, paginacao.QuantidadeRegistro);

            return(await queryable.Paginar(paginacao).ToListAsync());
        }
Пример #3
0
        public async Task <ActionResult <List <UsuarioDTO> > > Get([FromQuery] PaginacaoDTO paginacao)
        {
            var queryable = _db.Users.AsQueryable();

            await HttpContext.InserirParamentroPaginacaoResposta(queryable, paginacao.QuantidadeRegistro);

            return(await queryable.Paginar(paginacao).Select(x => new UsuarioDTO
            {
                IdUsuario = x.Id,
                Email = x.Email
            }).ToListAsync());
        }
Пример #4
0
 public static IQueryable <T> Paginar <T>(this IQueryable <T> queryable, PaginacaoDTO paginacao)
 {
     return(queryable.Skip((paginacao.Pagina - 1) * paginacao.QuantidadeRegistro)
            .Take(paginacao.QuantidadeRegistro));
 }