Ejemplo n.º 1
0
        protected void SetCssClasses(Question q)
        {
            List<string> cssClasses = new List<string> { "", "", "" }; //needs to be same amount as Answers (Question)

            for (int i = 0; i < q.CorrectAnswer.Count; i++)
            {
                string answer = q.CorrectAnswer[i];
                int index = q.Answers.IndexOf(answer);
                cssClasses[index] = "correctanswer";
            }

            for (int i = 0; i < q.UserInput.Count; i++)
            {
                string userInput = q.UserInput[i];
                if (!q.CorrectAnswer.Contains(userInput))
                {
                    int index = q.Answers.IndexOf(userInput);
                    cssClasses[index] = "incorrectanswer";
                }
            }
            q.CssClasses = cssClasses;
        }
Ejemplo n.º 2
0
        private void SetUserInput(List<Question> questions, Repeater rep)
        {
            for (int i = 0; i < questions.Count; i++ )
            {
                RepeaterItem item = rep.Items[i];
                CheckBox cBox1 = (CheckBox)item.FindControl("cbox1");
                CheckBox cBox2 = (CheckBox)item.FindControl("cbox2");
                CheckBox cBox3 = (CheckBox)item.FindControl("cbox3");

                Question q = new Question();
                List<string> list = new List<string>();
                q = questions[i];
                if (cBox1.Checked)
                    list.Add(cBox1.Text);

                if (cBox2.Checked)
                    list.Add(cBox2.Text);

                if (cBox3.Checked)
                    list.Add(cBox3.Text);

                q.UserInput = list;
                System.Web.UI.WebControls.Image image = (System.Web.UI.WebControls.Image)item.FindControl("questionImage");

                if (IsAnswersCorrect(q))
                {
                    q.IsCorrect = true;
                    q.ImageUrl = "~/img/btn_correct.png";
                    SetCssClasses(q);
                }
                else
                {
                    q.IsCorrect = false;
                    q.ImageUrl = "~/img/btn_incorrect.png";
                    SetCssClasses(q);
                }
            }
        }
Ejemplo n.º 3
0
 private bool IsAnswersCorrect(Question q)
 {
     if(q.CorrectAnswer.Count == q.UserInput.Count)
     {
         if (q.CorrectAnswer.OrderBy(x => x).SequenceEqual(q.UserInput.OrderBy(x => x)))
             return true;
         else
             return false;
     }
     else
     {
         return false;
     }
 }
Ejemplo n.º 4
0
        private Tuple<bool, Question> DoesAnswerExist(Question checkQuestion, List<Question> personsWithQuestions)
        {
            Question q = personsWithQuestions.FirstOrDefault(x => x.Id == checkQuestion.Id);
            if (q != null)
            {
                Tuple<bool, Question> tuple = new Tuple<bool, Question>(true,q);
                return tuple;
            }

            else
            {
                Tuple<bool, Question> tuple2 = new Tuple<bool, Question>(false, personsWithQuestions[0]);
                return tuple2;
            }
        }