Пример #1
0
        public QuestionSave(PerQuestionView view, QuizContext cx)
        {
            View = view;

            var question = cx.Questions.Find(view.Question.Id);

            QuestionId = question.Id;

            View.Test = new TestView()
            {
                Quiz     = question.Quiz,
                Question = question,
                Model    = XmlBase.Deserialize(question.XmlObject, question.TypeName),
                Save     = view.QuestionData
            };

            var xmlQuestion = XmlBase.Deserialize(question.XmlObject, question.TypeName);

            var answerType = XmlBase.GetType(((IAnswerName)xmlQuestion).GetTypeName());

            var answerInstance = (XmlBase)Activator.CreateInstance(answerType);

            ((IParseAnswer)answerInstance).ParseAnswer(view.QuestionData.Answers);

            Answer = answerInstance;
        }
Пример #2
0
        private void PerQuestion()
        {
            PerQuestionView model = null;

            Question question = null;

            if (_quiz.Type == QuizType.Adaptive)
            {
                question = _helper.GetQuestion_Adaptive(_quiz, null, null, out bool isFinish, true);

                model = new PerQuestionView()
                {
                    Question     = question,
                    Test         = _helper.CreateTestView(question),
                    QuestionData = new AnswerBaseView()
                };

                SessionSave = new TestSave(_cx);
            }
            else
            {
                var testSave = _helper.CreateWholeTest(_quiz);

                SessionSave = testSave;

                question = _cx.Questions.Find(SessionSave.QuestionOrders[0]);

                model = testSave.QuestionSaves[question.Id].View;
            }

            model = _helper.SetNavigation(model, question, SessionSave);

            PerQuestionModel = model;
        }
Пример #3
0
        public void Update(PerQuestionView view)
        {
            if (QuestionSaves.Keys.Contains(view.Question.Id))
            {
                QuestionSaves.Remove(view.Question.Id);
            }

            QuestionSaves.Add(view.Question.Id, new QuestionSave(view, _cx));
        }
Пример #4
0
        /// <summary>
        /// to initialize all test (need for time limit save)
        /// Not using for Adaptive quiz
        /// </summary>
        public TestSave CreateWholeTest(Quiz quiz)
        {
            var sections = cx.Sections.Where(x => x.Quiz.Id == quiz.Id).ToList();

            if (quiz.TestingType == QuizTestingType.PerSection)
            {
                var views = new List <SectionView>();

                foreach (var section in sections)
                {
                    var view = new SectionView()
                    {
                        QuizId      = quiz.Id,
                        SectionId   = section.Id,
                        Section     = section,
                        SectionData = new List <AnswerBaseView>(),
                    };

                    var questions = GetRandomSectionQuestions(section.Id);

                    view.Tests = CreateTestViews(questions, quiz);

                    views.Add(view);
                }

                return(new TestSave(cx, views));
            }
            else if (quiz.TestingType == QuizTestingType.PerQuestion)
            {
                var views = new List <PerQuestionView>();

                foreach (var section in sections)
                {
                    var questions = GetRandomSectionQuestions(section.Id);

                    foreach (var question in questions)
                    {
                        var view = new PerQuestionView()
                        {
                            Question     = question,
                            Test         = CreateTestView(question),
                            QuestionData = new AnswerBaseView(),
                        };

                        views.Add(view);
                    }
                }

                return(new TestSave(cx, views));
            }

            //Are you added new enum?
            throw new NotImplementedException();
        }
Пример #5
0
        public PerQuestionView SetNavigation(PerQuestionView model, Question question, TestSave testSave)
        {
            var quiz = question.Quiz;

            if (testSave.QuestionOrders.IndexOf(question.Id) ==
                testSave.QuestionOrders.Count - 1)
            {
                model.IsFinish = true;
                if (testSave.QuestionOrders.Count > 1)
                {
                    model.PrevVisibility = true;
                }
            }
            else
            {
                model.PrevVisibility = true;
                model.NextVisibility = true;
                if (testSave.QuestionOrders.IndexOf(question.Id) == 0)
                {
                    model.PrevVisibility = false;
                }
            }

            if (quiz.Type == QuizType.Adaptive)
            {
                model.PrevVisibility = false;

                model.IsFinish = false;

                model.NextVisibility = true;
            }

            if (quiz.TimeLimitType == QuizTimeLimitType.QuestionLimited)
            {
                model.PrevVisibility = false;
            }

            return(model);
        }
Пример #6
0
        public ActionResult TestQuestion(PerQuestionView view)
        {
            //saving session
            var testSave = (TestSave)Session["save"];

            view.Question = cx.Questions.Find(view.Question.Id);
            testSave.Update(view);
            Session["save"] = testSave;

            //choosing action
            helper.ChooseAction(
                view.Question,
                Request.Form["btnSubmit"],
                testSave,
                out bool isFinish, out Question nextQuestion);

            //finish view
            if (isFinish)
            {
                var finishView = new FinishView()
                {
                    Quiz = view.Question.Quiz,
                };

                var usedSections = new List <Section>();

                foreach (var question in testSave.QuestionSaves.
                         Select(x => cx.Questions.Find(x.Key)).
                         ToList())
                {
                    if (usedSections.Any(x => x.Id == question.Section.Id))
                    {
                        continue;
                    }
                    usedSections.Add(question.Section);
                }

                var sectionAnswersList = new List <SectionAnswersView>();

                foreach (var section in usedSections)
                {
                    var sectionAnswers = new SectionAnswersView()
                    {
                        Section = section,
                        QuestionIndex_IsInit = new Dictionary <int, bool>()
                    };

                    int index = 1;

                    var sectionIds = cx.Questions.
                                     Where(x => x.Section.Id == section.Id).
                                     Select(y => y.Id).ToList();

                    foreach (var questionAnswer in testSave.QuestionSaves.
                             Where(x => sectionIds.Contains(x.Key)).ToList())
                    {
                        sectionAnswers.QuestionIndex_IsInit.Add(
                            index,
                            ((IParseAnswer)questionAnswer.Value.Answer).IsValid()
                            );
                        index++;
                    }

                    sectionAnswersList.Add(sectionAnswers);
                }

                finishView.SectionAnswers = sectionAnswersList;

                ModelState.Clear();

                bool isEnded = false;

                if (Request.Form["btnSubmit"] == "QuizTime" ||
                    Request.Form["btnSubmit"] == "QuestionTime")
                {
                    isEnded = true;
                }

                ViewBag.isEnded = isEnded;

                return(PartialView("Finish", finishView));
            }

            //create model
            PerQuestionView model = null;

            if (testSave.QuestionSaves.ContainsKey(nextQuestion.Id))
            {
                model = testSave.QuestionSaves[nextQuestion.Id].View;
            }
            else
            {
                model = new PerQuestionView()
                {
                    Question = nextQuestion,
                };

                model.Test = helper.CreateTestView(nextQuestion);
            }

            model = helper.SetNavigation(model, nextQuestion, testSave);

            ModelState.Clear();

            return(PartialView("TestQuestion", model));
        }