public async Task <string> Handle(CreatePollRequest request, CancellationToken cancellationToken) { var(conferenceId, pollInstruction, pollConfig, initialState, roomId) = request; var pollId = Guid.NewGuid().ToString("N"); var timestamp = DateTimeOffset.UtcNow; var poll = new Poll(pollId, pollInstruction, pollConfig, roomId, timestamp); await _repository.CreatePoll(conferenceId, poll); await _repository.SetPollState(conferenceId, pollId, initialState); if (!await _openConferenceRepository.IsOpen(request.ConferenceId)) { await _repository.DeletePollAndState(conferenceId, pollId); throw ConferenceError.ConferenceNotOpen.ToException(); } await _mediator.Send(new UpdateParticipantSubscriptionsOfPollRequest(conferenceId, poll)); await SceneUpdater.UpdateScene(_mediator, conferenceId, roomId); return(pollId); }
public async Task <Unit> Handle(DeletePollRequest request, CancellationToken cancellationToken) { var(conferenceId, pollId) = request; var poll = await _repository.GetPoll(conferenceId, pollId); if (poll == null) { return(Unit.Value); } await _repository.DeletePollAndState(conferenceId, pollId); var deletedAnswers = await _repository.DeletePollAnswers(conferenceId, pollId); await _mediator.Send(new UpdateParticipantSubscriptionsOfPollRequest(conferenceId, poll)); await SceneUpdater.UpdateScene(_mediator, conferenceId, poll.RoomId); foreach (var participantId in deletedAnswers.Keys) { await _mediator.Send(new UpdateSynchronizedObjectRequest(conferenceId, SynchronizedPollAnswers.SyncObjId(participantId))); } return(Unit.Value); }
public async Task <Unit> Handle(UpdatePollStateRequest request, CancellationToken cancellationToken) { var(conferenceId, pollId, pollState) = request; var previousState = await _repository.SetPollState(conferenceId, pollId, pollState); var poll = await _repository.GetPoll(conferenceId, pollId); if (poll == null) { await _repository.DeletePollAndState(conferenceId, pollId); throw PollError.PollNotFound.ToException(); } await _mediator.Send(new UpdateSynchronizedObjectRequest(conferenceId, SynchronizedPoll.SyncObjId(pollId))); if (request.State.ResultsPublished != previousState?.ResultsPublished) { await _mediator.Send(new UpdateParticipantSubscriptionsOfPollRequest(conferenceId, poll)); } return(Unit.Value); }