public async Task <IActionResult> Get([FromQuery] PageParamsAlunos pageParams) { var alunos = await _repository.GetAllAlunosAsync(pageParams, true); var alunosResult = _mapper.Map <IEnumerable <AlunoDto> >(alunos); Response.AddPagination(alunos.CurrentPage, alunos.PageSize, alunos.TotalCount, alunos.TotalPages); return(Ok(alunosResult)); }
/// <summary> /// Repository - retorna dados de todos os alunos /// </summary> /// <param name="pageParams"></param> /// <param name="includeProfessor"></param> /// <returns></returns> public async Task <PageList <Aluno> > GetAllAlunosAsync(PageParamsAlunos pageParams, bool includeProfessor = false) { IQueryable <Aluno> query = _context.Alunos; if (includeProfessor) { query = query.Include(a => a.AlunosDisciplinas) .ThenInclude(ad => ad.Disciplina) .ThenInclude(p => p.Professor); } query = query.AsNoTracking().OrderBy(a => a.Id); if (!string.IsNullOrEmpty(pageParams.Nome)) { query = query.Where(aluno => aluno.Nome .ToUpper() .Contains(pageParams.Nome.ToUpper()) || aluno.Sobrenome .ToUpper() .Contains(pageParams.Nome.ToUpper())); } if (!string.IsNullOrEmpty(pageParams.Matricula)) { query = query.Where(aluno => aluno.Matricula .ToUpper() .Contains(pageParams.Matricula.ToUpper())); } if (pageParams.Ativo != null) { query = query.Where(aluno => aluno.Ativo == (pageParams.Ativo != 0)); } //query = query.OrderByDescending(o => o.DataIni).ThenBy(o => o.Matricula); return(await PageList <Aluno> .CreateAsync(query, pageParams.PageNumber, pageParams.PageSize)); }