Exemple #1
0
        public async Task <IActionResult> GetElectionById(int id)
        {
            var selectedElection = await _electionService.SelectElection(id);

            if (selectedElection == null)
            {
                return(NotFound($"Election with id {id} was not found."));
            }

            var response = new ElectionDetailResponse
            {
                Id          = selectedElection.Id,
                Description = selectedElection.Description,
                Date        = selectedElection.Date.ToShortDateString(),
                Results     = selectedElection.Candidacies.Select(c => new ElectionDetailResponse.CandidateItem {
                    FirstName = c.Candidate.Name.FirstName,
                    LastName  = c.Candidate.Name.LastName,
                    Votes     = c.Ballots.Count()
                })
            };

            return(Ok(response));
        }