Пример #1
0
        public async Task <PagedList <Candidato> > GetCandidatos(CandidatesParams cp)
        {
            var query = context.Candidatos.Where(x => !x.Deleted).AsNoTracking().AsQueryable();

            if (cp.Type > 0)
            {
                query = query.Where(x => x.TipoCandidato == cp.Type);
            }

            return(await PagedList <Candidato> .CreateAsync(query, cp.PageNumber, cp.PageSize));
        }
Пример #2
0
        public async Task <IActionResult> Index([FromQuery] CandidatesParams cp)
        {
            var result = await repo.GetCandidatos(cp);

            var webRootPath = environment.WebRootPath;

            Response.AddPagination(result.CurrentPage, result.PageSize, result.TotalCount, result.TotalPages);

            var candidatos = result.Select(x => new CandidatoDto
            {
                Id            = x.Id,
                Digito        = x.Digito,
                DataRegistro  = x.DataRegistro,
                Legenda       = x.Legenda,
                NomeCompleto  = x.NomeCompleto,
                NomeVice      = x.NomeVice != null ? x.NomeVice : "",
                TipoCandidato = x.TipoCandidato,
                FotoCandidato = Utils.SearchFile($"{x.Digito}_", webRootPath),
                FotoVice      = x.NomeVice != null ? Utils.SearchFile($"{x.Digito}_vice", webRootPath) : "",
            }).ToArray();

            return(Ok(new { candidatos }));
        }