Ejemplo n.º 1
0
        public IEnumerable <PersonQuestionAnswerView> GetPersonTestResult(int personId, int testId)
        {
            List <PersonQuestionAnswerView> res = new List <PersonQuestionAnswerView>();
            TestResult testResult = Database.TestResultRepository.Get(t => t.PersonId.Equals(personId) && t.Id.Equals(testId)).FirstOrDefault();

            if (testResult != null)
            {
                IEnumerable <TestQuestionAnswer> testQuestionAnswers = Database.TestQuestionAnswerRepository
                                                                       .GetWithInclude(tq => tq.TestResultId.Equals(testResult.Id), tq => tq.Question)?.ToArray();

                foreach (var item in testQuestionAnswers)
                {
                    PersonQuestionAnswerView personQuestionAnswerView = new PersonQuestionAnswerView();
                    personQuestionAnswerView.QuestionDescription = item.Question.Description;
                    personQuestionAnswerView.Answer1             = item.Question.Answer1;
                    personQuestionAnswerView.Answer2             = item.Question.Answer2;
                    personQuestionAnswerView.Answer3             = item.Question.Answer3;
                    personQuestionAnswerView.RightAnswerNum      = item.Question.RightAnswerNum;
                    personQuestionAnswerView.AnswerNum           = item.AnswerNum;
                    res.Add(personQuestionAnswerView);
                }
            }

            return(res);
        }
Ejemplo n.º 2
0
        public PersonQuestionAnswerView GetPrevQuestion(int curQuestionId)
        {
            Question question = new Question();

            question = Database.QuestionRepository.Get(q => q.Id < curQuestionId).OrderBy(p => p.Id).LastOrDefault();
            PersonQuestionAnswerView personQuestionAnswerView = PersonQuestionAnswerView.FromQuestion(question);

            return(personQuestionAnswerView);
        }
Ejemplo n.º 3
0
        public async Task <string> SaveQuestionAsnwer(PersonQuestionAnswerView personQuestionAnswer)
        {
            if (personQuestionAnswer.QuestionId != 0 && personQuestionAnswer.AnswerNum != 0)
            {
                int             testId = (int)Session[nameof(testId)];
                OperationResult result = await testService.AddQuestionAnswer(testId, personQuestionAnswer.QuestionId, personQuestionAnswer.AnswerNum);

                //if (result.Succeded)
                //{
                //     return RedirectToAction(nameof(this.DisplayNextQuestion), new { curQuestionId = personQuestionAnswer.QuestionId });
                //}
                return(result.Message);
            }
            return("error");
        }
Ejemplo n.º 4
0
        public ActionResult DisplayQuestionByNum(int num)
        {
            int  questionCount = testService.GetQuestionCount();
            bool isLast        = num > questionCount;

            if (isLast)
            {
                return(RedirectToAction(nameof(this.DisplayTestResults)));
            }
            else
            {
                PersonQuestionAnswerView personQuestion = testService.GetQuestionByNum(num);
                personQuestion.IsLast  = num.Equals(questionCount);
                personQuestion.IsFirst = num.Equals(1);
                ViewBag.qCount         = questionCount;
                int testId = (int)Session[nameof(testId)];
                personQuestion.AnswerNum = testService.GetAnswerNum(testId, personQuestion.QuestionId).GetValueOrDefault();
                return(View("DisplayQuestion", personQuestion));
            }
        }
Ejemplo n.º 5
0
 public PersonQuestionAnswerView GetQuestionByNum(int num)
 => PersonQuestionAnswerView.FromQuestion(Database.QuestionRepository.GetAll().OrderBy(q => q.Id).Skip(num - 1).Take(1).FirstOrDefault());