Пример #1
0
        public async Task <Election> AddCandidateToElection(int electionId, int candidateId)
        {
            // Get the election that we're going to use
            var election = await _electionRepository.FindById(electionId);

            if (election is null)
            {
                throw new KeyNotFoundException(nameof(electionId));
            }

            // Find the candidate (assumption: only adding existing candidates)
            var candidate = await _candidateRepository.FindById(candidateId);

            if (candidate is null)
            {
                throw new KeyNotFoundException(nameof(candidateId));
            }

            // Add the candidate to the election's list

            election.AddCandidate(candidate);

            await _electionRepository.UpdateElection(election);

            return(election);
        }
Пример #2
0
 public async Task UpdateElection(ElectionViewModel election)
 {
     await _electionRepository.UpdateElection(ElectionViewModel.ToDataModel(election));
 }