Ejemplo n.º 1
0
        protected void Button_Rep_Quizz_Click(object sender, EventArgs e)
        {
            int  score       = 0;
            int  nbQuestions = cQuizz.Questions.Count;
            bool allGood     = true;

            foreach (Question question in cQuizz.Questions)
            {
                Panel pQuestion = panel_Questions_Container.FindControl("Panel_Question_" + question.IdQuestion) as Panel;
                foreach (Answer answer in question.OtherAnsweres)
                {
                    CheckBox cbAnswer = pQuestion.FindControl("chb_isGood_" + question.IdQuestion + "_" + answer.IdAnswere) as CheckBox;
                    allGood = (cbAnswer.Checked == answer.isGoodAnswere);
                    if (!allGood)
                    {
                        break;
                    }
                }
                if (allGood)
                {
                    score++;
                }
            }


            ApplicationUser user = identityContext.GetByIdEager(User.Identity.GetUserId());

            if (user != null)
            {
                identityContext.addQuizzTaken(user.Id, cQuizz.IdQuizz, score, nbQuestions);
            }

            labelScore.Text    = "Score final : " + score + "/" + nbQuestions;
            labelScore.Visible = true;
        }