protected void btnNext_Click(object sender, EventArgs e) { //validate AnswerSheet answerSheet = AnswerHelper.GetAnswerSheet(this.UserId, this.ExamId); List <string> checkedOptionIds = new List <string>(); foreach (RepeaterItem item in repOptions.Items) { if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem) { var chkOption = item.FindControl("chkOption") as CheckBox; var litOptionId = item.FindControl("litOptionId") as Literal; if (chkOption.Checked) { checkedOptionIds.Add(litOptionId.Text); } } } if (checkedOptionIds.Count > 0) { if (answerSheet == null) { answerSheet = new AnswerSheet() { Answers = new List <Answer>() }; } if (!answerSheet.Answers.Any(x => x.QuestionId == litId.Text)) { answerSheet.Answers.Add(new Answer() { QuestionId = litId.Text, SelectedOptionIds = checkedOptionIds }); ExamHelper.SaveAnswerSheet(this.UserId, this.ExamId, answerSheet); } } _SetUIAndBindData(); }
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(); } }
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); } } }