Ejemplo n.º 1
0
        public async Task <ActionResult> NextQuestion(Guid QId, string QName, int QIndex, string Correct, int Score)
        {
            try
            {
                ScoreUser_VM score1 = new ScoreUser_VM()
                {
                    QName = QName, QId = QId, QIndex = QIndex
                };
                var questions = await _questionRepository.GetQuestionsForQuizAsync(score1.QId);

                score1.QIndex++;
                if (Correct == "correct")
                {
                    Score += 1;
                }
                if (score1.QIndex >= questions.Count())
                {
                    Score newscore = new Score()
                    {
                        ApplicationUserId = _userManager.GetUserId(User),
                        QuizId            = score1.QId,
                        MaxScore          = questions.Count(),
                        FinalScore        = Score
                    };
                    await _scoreRepository.AddScoreAsync(newscore);

                    return(View("ResultQuiz", newscore));
                }
                else
                {
                    var            objquestion = questions[score1.QIndex];
                    IList <Answer> answers     = await _answerRepository.GetAnswersForQuestionAsync(objquestion.Id.ToString());

                    score1.Question = objquestion;
                    score1.Answers  = answers;
                    ViewBag.score   = Score;
                    return(View("PlayQuiz", score1));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.InnerException.Message);
                return(View());
            }
        }