public async Task HandleAsync() { try { if (notice.OptionsId != null && notice.OptionsId.Any()) { await pollsService.VotePollAsync( notice.PollId, notice.ConversationId, notice.ConversationType, notice.OptionsId, notice.VotedUserId).ConfigureAwait(false); } else { await pollsService.VotePollAsync( notice.PollId, notice.ConversationId, notice.ConversationType, notice.SignedOptions, notice.VotedUserId).ConfigureAwait(false); } } catch (ObjectDoesNotExistsException) { var pollDto = await nodeRequestSender.GetPollInformationAsync( notice.ConversationId, notice.ConversationType, notice.PollId, nodeConnection).ConfigureAwait(false); await pollsService.SavePollAsync(pollDto).ConfigureAwait(false); } }
public async Task VotePoll() { var chat = fillTestDbHelper.Chats.FirstOrDefault(); var chatUser = chat.ChatUsers.LastOrDefault(); var poll = new PollDto { ConversationId = chat.Id, ConversationType = ConversationType.Chat, Title = "Poll", CreatorId = chatUser.UserId, Options = new List<PollOptionDto> { new PollOptionDto { Description = "desc", OptionId = 1 }, new PollOptionDto { Description = "desc 2", OptionId = 2 } } }; poll = await pollsService.SavePollAsync(poll); var votedPoll = await pollsService.VotePollAsync(poll.PollId, poll.ConversationId, poll.ConversationType, new List<byte> { 1 }, chatUser.UserId); Assert.NotNull(votedPoll.Options.FirstOrDefault(opt => opt.OptionId == 1).Votes.FirstOrDefault(opt => opt.UserId == chatUser.UserId)); }
public async Task <Response> CreateResponseAsync() { try { PollDto poll; poll = await pollsService.VotePollAsync( request.PollId, request.ConversationId, request.ConversationType, request.Options, clientConnection.UserId.GetValueOrDefault()).ConfigureAwait(false); List <long> nodesId = null; switch (poll.ConversationType) { case ConversationType.Chat: { nodesId = await loadChatsService.GetChatNodeListAsync(poll.ConversationId).ConfigureAwait(false); } break; case ConversationType.Channel: { nodesId = await loadChannelsService.GetChannelNodesIdAsync(poll.ConversationId).ConfigureAwait(false); } break; } nodeNoticeService.SendPollingNodeNoticeAsync( poll.PollId, poll.ConversationId, poll.ConversationType, request.Options, clientConnection.UserId.GetValueOrDefault(), nodesId); return(new PollResponse(request.RequestId, PollConverter.GetPollVm(poll, clientConnection.UserId.GetValueOrDefault()))); } catch (PermissionDeniedException ex) { return(new ResultResponse(request.RequestId, ex.Message, ErrorCode.PermissionDenied)); } catch (ObjectDoesNotExistsException ex) { return(new ResultResponse(request.RequestId, ex.Message, ErrorCode.ObjectDoesNotExists)); } catch (InvalidOperationException ex) { return(new ResultResponse(request.RequestId, ex.Message, ErrorCode.InvalidArgument)); } catch (InvalidSignException ex) { return(new ResultResponse(request.RequestId, ex.Message, ErrorCode.InvalidSign)); } }