Exemple #1
0
        public AnswerBase AddAnswer(QuestionBase question, string answerText, bool isCorrect)
        {
            int maxAnswerId = 0;

            if (question.GetAnswers().Count > 0)
            {
                maxAnswerId = question.GetAnswers().Max(x => x.Id);
            }
            var answer = new AnswerBase(maxAnswerId + 1, answerText, isCorrect);

            question.AddAnswer(answer);
            return(answer);
        }
        internal List<AnswerBase> GetAnswers()
        {
            List<AnswerBase> output = new List<AnswerBase>();
            foreach (GridViewRow row in gvQuestions.Rows)
            {
                AnswerBase answer = new AnswerBase();
                answer.QuestionId = Convert.ToInt32(gvQuestions.DataKeys[row.RowIndex].Value.ToString());

                RadioButtonList rbRatings = (RadioButtonList)
                    row.Cells[ColumnRatings].FindControl("rbRatings");
                if (rbRatings.Visible)
                {
                    answer.AnswerType = AssessmentQuestion.AnswerTypes.R;
                    answer.Value = rbRatings.SelectedValue.ToString();
                }
                else
                {
                    answer.AnswerType = AssessmentQuestion.AnswerTypes.T;
                    TextBox txt =
                        (TextBox)row.Cells[ColumnTextAnswer].FindControl("txtAnswer");
                    answer.Value = txt.Text;
                }

                answer.Username = Page.User.Identity.Name;
                output.Add(answer);
            }
            return output;
        }
Exemple #3
0
        public bool ValidateAnswer(AnswerBase answer)
        {
            if (!Mandatory)
                return true; // if not mandatory always return true

            bool isBlankAnswer = false;
            if (answer.AnswerType == AssessmentQuestion.AnswerTypes.R &&
                answer.Value == "0")
                isBlankAnswer = true;
            else if (answer.AnswerType == AssessmentQuestion.AnswerTypes.T &&
                string.IsNullOrEmpty(answer.Value))
                isBlankAnswer = true;
            return !isBlankAnswer;
        }