public async Task <PagedList <Atleta> > GetAtletas(AtletaParams atletaParams) { var atletas = _context.Atletas.Include(x => x.Posicao) .OrderByDescending(u => u.Numero).AsQueryable(); atletas = atletas.Where(u => u.Id != atletaParams.AtletaId); if (atletaParams.Posicao != null) { atletas = atletas.Where(u => u.Posicao.NomePosicao == atletaParams.Posicao); } if (atletaParams.AnoMin != 1950 || atletaParams.Anomax != 2099) { atletas = atletas.Where(u => u.DataNascimento.Year >= atletaParams.NumeroMin && u.DataNascimento.Year <= atletaParams.NumeroMax); } if (!string.IsNullOrEmpty(atletaParams.OrderBy)) { switch (atletaParams.OrderBy) { case "created": atletas = atletas.OrderByDescending(u => u.Numero); break; default: atletas = atletas.OrderByDescending(u => u.DataNascimento); break; } } return(await PagedList <Atleta> .CreateAsync(atletas, atletaParams.PageNumber, atletaParams.PageSize)); }
public async Task <IActionResult> GetAtletas([FromQuery] AtletaParams atletaParams) { // var currentAtletaId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); // var atletaFromRepo = await _repo.GetAtleta(currentAtletaId); // atletaParams.AtletaId = currentAtletaId; var atletas = await _repo.GetAtletas(atletaParams); Response.AddPagination(atletas.CurrentPage, atletas.PageSize, atletas.TotalCount, atletas.TotalPages); return(Ok(atletas)); }