Exemple #1
0
        public void UpdateResponse(QuestionProposedAnswersViewModel questionOptionsViewModel)
        {
            //OnlineExamAppDBEntities3 dbContext = new OnlineExamAppDBEntities3();

            if (_userResponseHeader == null)
            {
                _userResponseHeader             = new UserResponseHeader();
                _userResponseHeader.ExamID      = _exam.ID;
                _userResponseHeader.AttemptedOn = DateTime.Today;

                //dbContext.UserResponseHeaders.Add(_userResponseHeader);
            }

            UserResponseDetail userResponseDetail = null;

            foreach (ProposedAnswerViewModel optionViewModel in questionOptionsViewModel.ProposedAnswers)
            {
                if (!optionViewModel.IsSelected)
                {
                    continue;
                }

                userResponseDetail = new UserResponseDetail();
                userResponseDetail.UserResponseHeader = _userResponseHeader;
                userResponseDetail.QuestionID         = questionOptionsViewModel.Question.ID;
                userResponseDetail.AnswerID           = optionViewModel.ID;

                _userResponseHeader.UserResponseDetails.Add(userResponseDetail);
            }

            //dbContext.SaveChanges();
        }
        public ActionResult NextQuestion(int?questionId)
        {
            ExamManagerEF examManagerEF = examUtil.GetExamManager();
            QuestionProposedAnswersViewModel questionOptionsViewModel = examManagerEF.GetQuestion(questionId);

            ViewBag.UserName = examManagerEF.LoggedInUser.Name;

            return(View(questionOptionsViewModel));
        }
        public ActionResult SaveUserResponse(QuestionProposedAnswersViewModel questionOptionsViewModel)
        {
            ExamManagerEF examManagerEF = Session["ExamManager"] as ExamManagerEF;

            examManagerEF.UpdateResponse(questionOptionsViewModel);

            if (!examManagerEF.IsLastQuestion(questionOptionsViewModel.Question.ID))
            {
                return(this.RedirectToAction("NextQuestion", new { questionId = questionOptionsViewModel.Question.ID }));
            }
            else
            {
                return(this.RedirectToAction("EvaluateExam"));
            }
        }
Exemple #4
0
        private QuestionProposedAnswersViewModel GetQuestionViewModel(OnlineExamAppDBEntities3 dbContext, Question question)
        {
            QuestionProposedAnswersViewModel questionOptionsViewModel = new QuestionProposedAnswersViewModel();
            List <ProposedAnswerViewModel>   options = new List <ProposedAnswerViewModel>();

            questionOptionsViewModel.Question = new QuestionViewModel()
            {
                ID = question.ID, Text = question.QuestionText
            };

            List <QuestionProposedAnswer> questionProposedAnswers = dbContext.QuestionProposedAnswers.Where(qpa => qpa.QuestionID == question.ID).ToList <QuestionProposedAnswer>();

            foreach (QuestionProposedAnswer questionProposedAnswer in questionProposedAnswers)
            {
                options.Add(new ProposedAnswerViewModel()
                {
                    ID = questionProposedAnswer.ProposedAnswer.ID, Text = questionProposedAnswer.ProposedAnswer.AnswerText
                });
            }

            questionOptionsViewModel.ProposedAnswers = options;
            return(questionOptionsViewModel);
        }