Beispiel #1
0
 public static Exm ProcessAnswers(Exm exam, AnswerSheet answersheet)
 {
     foreach (Question question in exam.Questions)
     {
         foreach (Answer answer in answersheet.Answers)
         {
             if (answer.QuestionId == question.Id)
             {
                 bool isAnswerCorrect = true;
                 foreach (Option opt in question.Options)
                 {
                     if (opt.IsCorrect)
                     {
                         if (!answer.SelectedOptionIds.Contains(opt.Id))
                         {
                             isAnswerCorrect = false;
                         }
                     }
                     else
                     {
                         if (answer.SelectedOptionIds.Contains(opt.Id))
                         {
                             isAnswerCorrect = false;
                         }
                     }
                 }
                 question.CalculatedScore = isAnswerCorrect ? question.Score.True : question.Score.False;
                 question.SubmittedAnswer = answer;
             }
         }
     }
     return(exam);
 }
Beispiel #2
0
        public static int SaveAnswerSheet(int userId, int examId, AnswerSheet answerSheet)
        {
            //get Score
            Exm exam  = GetExam(examId);
            int score = CalculateScore(exam, answerSheet);

            return(ExamResultDBHelper.SaveAnswers(userId, examId, answerSheet.ToString(), score));
        }
Beispiel #3
0
        public static Exm GetExam(int examId)
        {
            string examXml = ExamDBHelaper.GetExam(examId);

            if (!string.IsNullOrEmpty(examXml))
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(examXml);

                Exm exam = Exm.Populate(doc);
                return(exam);
            }
            return(null);
        }
Beispiel #4
0
        public static int CalculateScore(Exm exam, AnswerSheet answersheet)
        {
            int score = 0;

            foreach (Question question in exam.Questions)
            {
                foreach (Answer answer in answersheet.Answers)
                {
                    if (answer.QuestionId == question.Id)
                    {
                        bool isAnswerCorrect = true;
                        foreach (Option opt in question.Options)
                        {
                            if (opt.IsCorrect)
                            {
                                if (!answer.SelectedOptionIds.Contains(opt.Id))
                                {
                                    isAnswerCorrect = false;
                                }
                            }
                            else
                            {
                                if (answer.SelectedOptionIds.Contains(opt.Id))
                                {
                                    isAnswerCorrect = false;
                                }
                            }
                        }
                        if (isAnswerCorrect)
                        {
                            score += question.Score.True;
                        }
                        else
                        {
                            score += question.Score.False;
                        }
                    }
                }
            }
            return(score);
        }
Beispiel #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Exm exam = ExamHelper.GetExam(this.ExamId);

            if (IsAnswerMode)
            {
                AnswerSheet answersheet = AnswerHelper.GetAnswerSheet(this.SubmittedUserId, this.ExamId);
                //feed submitted answers
                exam = ExamHelper.ProcessAnswers(exam, answersheet);
                divExamDetails.Visible = false;
            }

            if (exam != null)
            {
                litIstructions.Text = exam.Instructions != null ? exam.Instructions : "-";
                litTime.Text        = exam.TimeInSeconds.HasValue ? Utils.TimeString(exam.TimeInSeconds.Value) : "-";

                repQuestions.DataSource = exam.Questions;
                repQuestions.DataBind();
            }
        }
Beispiel #6
0
 public static Question NextQuestion(Exm exam, AnswerSheet answersheet)
 {
     foreach (Question question in exam.Questions)
     {
         bool unAnswered = true;
         if (answersheet != null)
         {
             foreach (Answer answer in answersheet.Answers)
             {
                 if (answer.QuestionId == question.Id)
                 {
                     unAnswered = false;
                 }
             }
         }
         if (unAnswered)
         {
             return(question);
         }
     }
     return(null);
 }
Beispiel #7
0
        private void _SetUIAndBindData()
        {
            Exm exam = ExamHelper.GetExam(this.ExamId);

            AnswerSheet answersheet = AnswerHelper.GetAnswerSheet(this.UserId, this.ExamId);

            if (!Page.IsPostBack)
            {
                divQuestionContainer.Visible = false;
                divMessage.Visible           = false;
                divWelcome.Visible           = true;

                litIstructions.Text = exam.Instructions != null ? exam.Instructions : "-";
                litTime.Text        = exam.TimeInSeconds.HasValue ? Utils.TimeString(exam.TimeInSeconds.Value) : "-";
                return;
            }
            else if (answersheet != null && answersheet.Answers.Count == exam.Questions.Count)
            {
                divQuestionContainer.Visible = false;
                divMessage.Visible           = true;
                divWelcome.Visible           = false;

                //lblMessage.Text = "Finished!";
            }
            else if (answersheet == null || answersheet.Answers.Count < exam.Questions.Count)
            {
                divQuestionContainer.Visible = true;
                divMessage.Visible           = false;
                divWelcome.Visible           = false;
                Question question = ExamHelper.NextQuestion(exam, answersheet);
                if (question != null)
                {
                    populateQuestionUI(question);
                }
            }
        }