Esempio n. 1
0
        public async Task GetResultsAsync(string id)
        {
            if (id == HubConstants.Active)
            {
                var activeQuiz = await _quizDataContext.GetActiveQuizAsync();

                if (activeQuiz != null)
                {
                    await Groups.AddToGroupAsync(Context.ConnectionId, HubConstants.Active);

                    var quiz = QuizViewModel.FromJson(activeQuiz.Json);
                    id = quiz.ID;

                    var counter = await _quizDataContext.GetConnectionCountAsync();

                    await Clients.Caller.SendAsync(HubConstants.ConnectedMethod, new ConnectionViewModel()
                    {
                        Counter = counter
                    });
                }
            }

            await Groups.AddToGroupAsync(this.Context.ConnectionId, id);

            var resultsBuilder = new QuizResultBuilder(_quizDataContext);
            var results        = await resultsBuilder.GetResultsAsync(id);

            await Clients.Caller.SendAsync(HubConstants.ResultsMethod, results);
        }
Esempio n. 2
0
        public async Task <IActionResult> Activate(string id)
        {
            var quiz = await _quizDataContext.ActivateQuizAsync(id);

            quiz ??= QuizViewModel.CreateBlank();

            await _quizHub.Clients.All.Quiz(quiz);

            if (quiz != null)
            {
                var resultsBuilder = new QuizResultBuilder(_quizDataContext);
                var results        = await resultsBuilder.GetResultsAsync(quiz.ID);

                await _quizResultsHub.Clients.Group(HubConstants.Active).SendAsync(HubConstants.ResultsMethod, results);
            }

            return(View(quiz));
        }
Esempio n. 3
0
        public async Task QuizResponse(ResponseViewModel quizResponse)
        {
            if (quizResponse == null)
            {
                throw new ArgumentNullException(nameof(quizResponse));
            }

            await _quizDataContext.UpsertResponseAsync(quizResponse);

            await Clients.Caller.Quiz(QuizViewModel.CreateBlank());

            // Submit this response to the reports view
            var resultsBuilder = new QuizResultBuilder(_quizDataContext);
            var results        = await resultsBuilder.GetResultsAsync(quizResponse.ID);

            await _quizResultsHub.Clients.Group(HubConstants.Active).SendAsync(HubConstants.ResultsMethod, results);

            await _quizResultsHub.Clients.Group(quizResponse.ID).SendAsync(HubConstants.ResultsMethod, results);
        }