/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { //Clear all validation errors lblAnswer3Required.Visible = false; lblAnswer4Required.Visible = false; lblInvalidAnswer.Visible = false; //start nested validation if (Page.IsValid) { if (IsCorrectAnswerValid()) { if (IsAnswerListValid()) { //We can now save the question var oInfo = new QuizQuestionInfo { QuestionId = _questionId, QuizId = _quizId, ModuleId = this.ModuleId, PromptText = txtPromptTextRich.Text, Answer1 = txtAnswer1.Text, Answer2 = txtAnswer2.Text, Answer3 = txtAnswer3.Text, Answer4 = txtAnswer4.Text, Answer5 = txtAnswer5.Text }; //Save the correct answer switch (ddlCorrectAnswer.SelectedValue) { case "1": oInfo.CorrectAnswer = txtAnswer1.Text; break; case "2": oInfo.CorrectAnswer = txtAnswer2.Text; break; case "3": oInfo.CorrectAnswer = txtAnswer3.Text; break; case "4": oInfo.CorrectAnswer = txtAnswer4.Text; break; case "5": oInfo.CorrectAnswer = txtAnswer5.Text; break; } //Persist value QuizController.SaveQuestion(oInfo); //Call cancel to redirect btnCancel_Click(sender, e); } } } }
/// <summary> /// This method returns a listing of the answers, with correct and user answers /// </summary> /// <param name="oQuestion"></param> /// <returns></returns> private List<string> LoadQuestionWithCorrectUserAnswer(QuizQuestionInfo oQuestion) { var answerList = new List<string>(); //Grab the users answer var oUserInfo = _answers[_questionIndex]; var yourCorrectAnswer = Localization.GetString("YourCorrectAnswer", LocalResourceFile); var correctAnswer = Localization.GetString("CorrectAnswer", LocalResourceFile); var yourAnswer = Localization.GetString("YourAnswer", LocalResourceFile); //First two, simply check for answer if (oQuestion.Answer1 == oQuestion.CorrectAnswer) { if (oQuestion.Answer1 == oUserInfo.Answer) answerList.Add(oQuestion.Answer1 + yourCorrectAnswer); else answerList.Add(oQuestion.Answer1 + correctAnswer); } else { if (oQuestion.Answer1 == oUserInfo.Answer) answerList.Add(oQuestion.Answer1 + yourAnswer); else answerList.Add(oQuestion.Answer1); } if (oQuestion.Answer2 == oQuestion.CorrectAnswer) { if (oQuestion.Answer2 == oUserInfo.Answer) answerList.Add(oQuestion.Answer2 + yourCorrectAnswer); else answerList.Add(oQuestion.Answer2 + correctAnswer); } else { if (oQuestion.Answer2 == oUserInfo.Answer) answerList.Add(oQuestion.Answer2 + yourAnswer); else answerList.Add(oQuestion.Answer2); } //Remaining three, check for existing and answer if (oQuestion.Answer3.Length > 0 & oQuestion.Answer3 == oQuestion.CorrectAnswer) { if (oQuestion.Answer3 == oUserInfo.Answer) answerList.Add(oQuestion.Answer3 + yourCorrectAnswer); else answerList.Add(oQuestion.Answer3 + correctAnswer); } else if (oQuestion.Answer3.Length > 0) { if (oQuestion.Answer3 == oUserInfo.Answer) answerList.Add(oQuestion.Answer3 + yourAnswer); else answerList.Add(oQuestion.Answer3); } if (oQuestion.Answer4.Length > 0 & oQuestion.Answer4 == oQuestion.CorrectAnswer) { if (oQuestion.Answer4 == oUserInfo.Answer) answerList.Add(oQuestion.Answer4 + yourCorrectAnswer); else answerList.Add(oQuestion.Answer4 + correctAnswer); } else if (oQuestion.Answer4.Length > 0) { if (oQuestion.Answer4 == oUserInfo.Answer) answerList.Add(oQuestion.Answer4 + yourAnswer); else answerList.Add(oQuestion.Answer4); } if (oQuestion.Answer5.Length > 0 & oQuestion.Answer5 == oQuestion.CorrectAnswer) { if (oQuestion.Answer5 == oUserInfo.Answer) answerList.Add(oQuestion.Answer5 + yourCorrectAnswer); else answerList.Add(oQuestion.Answer5 + correctAnswer); } else if (oQuestion.Answer5.Length > 0) { if (oQuestion.Answer5 == oUserInfo.Answer) answerList.Add(oQuestion.Answer5 + yourAnswer); else answerList.Add(oQuestion.Answer5); } return answerList; }
/// <summary> /// This method returns the questions /// </summary> /// <param name="oQuestion"></param> /// <returns></returns> private List<string> LoadQuestion(QuizQuestionInfo oQuestion) { //Start with the first two var answerList = new List<string> {oQuestion.Answer1, oQuestion.Answer2}; //Remaining three, check for data then add if (oQuestion.Answer3.Length > 0) answerList.Add(oQuestion.Answer3); if (oQuestion.Answer4.Length > 0) answerList.Add(oQuestion.Answer4); if (oQuestion.Answer5.Length > 0) answerList.Add(oQuestion.Answer5); return answerList; }
/// <summary> /// Saves the question. /// </summary> /// <param name="oInfo">The o info.</param> public static void SaveQuestion(QuizQuestionInfo oInfo) { DataProvider.Instance().SaveQuestion(oInfo.QuestionId, oInfo.QuizId, oInfo.ModuleId, oInfo.PromptText, oInfo.Answer1, oInfo.Answer2, oInfo.Answer3, oInfo.Answer4, oInfo.Answer5, oInfo.CorrectAnswer); }