示例#1
0
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var electionResult = await _electionService.GetElectionResultsByIdAsync(id.Value);

            string electionName = (await _electionService.GetElectionByIdAsync(id)).Name;

            Election election = await _electionService.GetElectionByConditionAsync(e => e.Id == id.Value).Result.Include(e => e.ElectionCadidate)
                                .ThenInclude(ec => ec.Candidate).ThenInclude(c => c.PoliticParty).FirstOrDefaultAsync();

            var candidatess = election.ElectionCadidate.Select(ec => ec.Candidate).ToList();

            var Votes = electionResult.Select(e => e.Candidate).GroupBy(c => c.Position.Name).ToList();
            ResultDetailViewMode resultDetailViewMode = new ResultDetailViewMode {
                Votes = Votes, Name = electionName, Candidates = candidatess
            };

            if (electionResult == null)
            {
                ViewBag.Message = "No se encontro ningun resultado de esa eleccion.";
                return(RedirectToAction(nameof(ElectionsList)));
            }

            return(View(resultDetailViewMode));
        }