public async Task <IActionResult> Index([FromQuery] VotesParams vp) { ICollection <Candidato> votes = new List <Candidato>(); ICollection <Voto> nulls = new List <Voto>(); ICollection <Voto> brancos = new List <Voto>(); if (vp.Type < 3) { votes = await repo.GetVotos(vp); nulls = await repo.GetCountVotosNulos(); brancos = await repo.GetCountVotosBrancos(); } else if (vp.Type == 3) { nulls = await repo.GetCountVotosNulos(); brancos = await repo.GetCountVotosBrancos(); } return(Ok(new { votes, nulls, brancos })); }
public async Task <ICollection <Candidato> > GetVotos(VotesParams vp) { var candidatos = context.Candidatos .Where(x => !x.Deleted) .Include(x => x.VotosRecebidos) .OrderByDescending(x => x.NomeCompleto) .AsNoTracking() .AsQueryable(); if (vp.Type == 1) { candidatos = candidatos.Where(x => vp.Type == x.TipoCandidato); } else if (vp.Type == 2) { candidatos = candidatos.Where(x => vp.Type == x.TipoCandidato); } return(await candidatos.ToListAsync()); }