Ejemplo n.º 1
0
 public async Task SavePoll()
 {
     var chat = fillTestDbHelper.Chats.FirstOrDefault();
     var chatUser = chat.ChatUsers.FirstOrDefault();
     var expectedPoll = 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
             }
         }
     };
     var actualPoll = await pollsService.SavePollAsync(expectedPoll);
     Assert.True(actualPoll.Title == expectedPoll.Title 
         && expectedPoll.ConversationId == actualPoll.ConversationId
         && expectedPoll.ConversationType == actualPoll.ConversationType
         && expectedPoll.CreatorId == actualPoll.CreatorId);
 }
Ejemplo n.º 2
0
        private async Task DownloadPollAttachmentAsync(AttachmentVm attachment, NodeConnection connection)
        {
            if (attachment.Payload is PollVm pollVm)
            {
                PollDto pollDto = await _nodeRequestSender.GetPollInformationAsync(
                    pollVm.ConversationId.Value,
                    pollVm.ConversationType.Value,
                    pollVm.PollId.Value,
                    connection).ConfigureAwait(false);

                await _pollsService.SavePollAsync(pollDto).ConfigureAwait(false);
            }
        }
        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);
            }
        }