public async Task <Response <Guid> > Handle(CreateVoter request, CancellationToken cancellationToken)
        {
            var exists = await _voters.Exists(request.Pesel);

            if (exists)
            {
                return(ObjectAlreadyExistsError.CreateFor <Voter>());
            }

            var voter = Voter.Create(request.Pesel);

            await _domainEvents
            .CollectFrom(voter)
            .PublishCollected(cancellationToken);

            return(voter.Id);
        }
Exemple #2
0
        public void Initialize()
        {
            if (this.context.Elections.Count() > 0)
            {
                return;
            }

            var studentRepElection = Election.CreateNew("Student Representative Election 2017", "The RCA Service Design MA2 are electing a new student representative. This election excepts votes till 6pm.");

            //Candidates
            var testCandidate1 = Candidate.CreateNew("Test", "Candidate 1", "*****@*****.**");

            studentRepElection.AddCandidate(testCandidate1);

            var testCandidate2 = Candidate.CreateNew("Test", "Candidate 2", "*****@*****.**");

            studentRepElection.AddCandidate(testCandidate2);

            var testCandidate3 = Candidate.CreateNew("Test", "Candidate 3", "*****@*****.**");

            studentRepElection.AddCandidate(testCandidate3);

            // Voters
            var voter1 = Voter.Create("Florian", "Tiefenbach", "*****@*****.**");

            studentRepElection.AddVote(voter1, this.codeGenerator);

            var voter2 = Voter.Create("Test", "Voter 1", "*****@*****.**");

            studentRepElection.AddVote(voter2, this.codeGenerator);

            var voter3 = Voter.Create("Test", "Voter 2", "*****@*****.**");

            studentRepElection.AddVote(voter3, this.codeGenerator);

            this.context.Elections.Add(studentRepElection);
            this.context.SaveChanges();
        }