Beispiel #1
0
        public async Task <Election> InsertElectionAsync(Election election, List <Candidate> electionCandidates, List <Position> electionPosition)
        {
            election.Date     = DateTime.Now;
            election.IsActive = true;
            Election result = await Task.FromResult(_electionRepository.Insert(election));

            if (result != null)
            {
                List <ElectionCadidate> cadidates = electionCandidates.Select(e => new ElectionCadidate {
                    CandidateId = e.Id, ElectionId = result.Id
                }).ToList();
                List <ElectionPosition> postions = electionPosition.Select(p => new ElectionPosition {
                    PositionId = p.Id, ElectionId = result.Id
                }).ToList();
                _electionCandidateRepository.Insert(cadidates);
                _electionPositionRepository.Insert(postions);
            }
            return(result);
        }