示例#1
0
        protected void SubmitBtn_Click(object sender, EventArgs e)
        {
            List <UserAnswer> userAnswers = new List <UserAnswer>();

            logger.Debug("controls length: " + controls.Count);
            foreach (var item in controls)
            {
                if (item is KeywordAnswer)
                {
                    string questionId = ((KeywordAnswer)item).ID;
                    string answer     = ((KeywordAnswer)item).Answer;
                    userAnswers.Add(new UserAnswer()
                    {
                        QuizId = quizId, QuizQuestionId = questionId, QuizUserAnswer = answer
                    });

                    logger.Info("userId: {2}, KeywordAnswer questionId: {0}, answer: {1}", questionId, answer, SessionVariable.Current.User.Id);
                }

                if (item is SingleSelectAnswer)
                {
                    string questionId = ((SingleSelectAnswer)item).ID;
                    string answer     = ((SingleSelectAnswer)item).Answer;
                    userAnswers.Add(new UserAnswer()
                    {
                        QuizId = quizId, QuizQuestionId = questionId, QuizUserAnswer = answer
                    });

                    logger.Info("userId: {2}, SingleSelectAnswer questionId: {0}, answer: {1}", questionId, answer, SessionVariable.Current.User.Id);
                }

                if (item is MultiSelectAnswer)
                {
                    string questionId = ((MultiSelectAnswer)item).ID;
                    string answer     = ((MultiSelectAnswer)item).Answer;
                    userAnswers.Add(new UserAnswer()
                    {
                        QuizId = quizId, QuizQuestionId = questionId, QuizUserAnswer = answer
                    });

                    logger.Info("userId: {2}, MultiSelectAnswer questionId: {0}, answer: {1}", questionId, answer, SessionVariable.Current.User.Id);
                }
            }

            try
            {
                LessonService.Grade(SessionVariable.Current.User.Id, quizId, lessonId, enrollmentId, userAnswers);
            }
            catch (DbEntityValidationException dvex)
            {
                foreach (var eve in dvex.EntityValidationErrors)
                {
                    logger.Error("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                 eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        logger.Error("- Property: \"{0}\", Error: \"{1}\"",
                                     ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }


            Response.Redirect("Curriculum?enid=" + enrollmentId);
        }