public async Task <Response <Guid> > Handle(CreateQuestion request, CancellationToken cancellationToken)
        {
            var question = Question.Create(request.QuestionText, request.Answers);

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

            return(question.Id);
        }
        public async Task Handle(VotePosted notification, CancellationToken cancellationToken)
        {
            var answer = await _answersRepository.Get(notification.AnswerId) !;

            if (answer is null)
            {
                throw new NullReferenceException(
                          $"answer with id {notification.AnswerId} was not found");
            }

            answer.IncrementVotes();

            await _domainEvents
            .CollectFrom(answer)
            .PublishCollected(cancellationToken);
        }
        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);
        }
Ejemplo n.º 4
0
        public override async Task <Response <Empty> > Handle(VoteFor request, CancellationToken cancellationToken)
        {
            var identity = _identityService.GetIdentity();

            var voter = await _votersRepository.Get(identity.Id);

            if (voter is null)
            {
                throw new NullReferenceException(
                          "cannot find voter with specified id");
            }

            var vote = voter.Vote(
                voter.Id,
                request.QuestionId,
                request.AnswerId);

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

            return(Success());
        }