protected override async Task OnInitializedAsync()
        {
            Guid guidFromParams = Guid.Empty;

            try
            {
                guidFromParams = new Guid(Id);
                Poll           = await GetPollByIdAsync(guidFromParams);
            }
            catch (Exception e)
            {
                // When Guid creation or http call fails
                Poll = null;
            }

            if (Poll != null)
            {
                _pollHubService = new PollHubService(NavigationManager.ToAbsoluteUri("/pollhub").ToString());
                await _pollHubService.StartPollHubConnection(Poll);

                _pollHubService.PollChanged += async(poll) => await VisualizePollChild.UpdatePoll(poll);
            }

            var pageCount = (double)Poll.Comments.Count() / PageSize;
            var lastPage  = pageCount == 0 ? 1 : (int)Math.Ceiling(pageCount);

            await LoadPaginatedComments(lastPage);
        }
Beispiel #2
0
        public async Task <bool> SendSinglePollAnswer(Poll poll, Answer answer, IPollHubService pollHubService)
        {
            var resp = await _httpClient.PutAsync($"/api/polls/{poll.Id}/vote-single/{answer.Id}", GetStringContent(answer));

            if (resp.IsSuccessStatusCode)
            {
                var updatedPoll = await FindPollById(poll.Id);

                await pollHubService.Send(updatedPoll);
            }

            return(resp.IsSuccessStatusCode);
        }
Beispiel #3
0
        public async Task <bool> SendMultiplePollAnswers(Poll poll, List <Answer> answers, IPollHubService pollHubService)
        {
            var ids = GetIdArrayFromAnswerList(answers);

            var resp = await _httpClient.PutAsync($"/api/polls/{poll.Id}/vote-multiple", GetStringContent(ids));

            if (resp.IsSuccessStatusCode)
            {
                var updatedPoll = await FindPollById(poll.Id);

                await pollHubService.Send(updatedPoll);
            }

            return(resp.IsSuccessStatusCode);
        }