Пример #1
0
        private string AnswerContentJSONToString(ExamAnswerDTO examAnswer, double score, string time)
        {
            ReviewExamDetailDTO reviewExamDetail = new ReviewExamDetailDTO();

            reviewExamDetail.Name  = examService.IsRandom(examAnswer.ExamId) ? examRepository.GetRandomExam(examAnswer.ExamId).Name : examRepository.Get(examAnswer.ExamId).Name;
            reviewExamDetail.Score = score;
            reviewExamDetail.Time  = time;
            for (int questionIndex = 0; questionIndex < examAnswer.AnswerDetails.Count; questionIndex++)
            {
                /**
                 * Create new Question to add to review questions
                 * Create List answer to add to answers of questions above
                 * Get Userquestion with full information
                 * in question loop though set of answers to get information and add to list answer above
                 * assign list answer to question
                 * fill the rest of information for question
                 * add question to list
                 */
                ReviewQuestionDTO      reviewQuestion = new ReviewQuestionDTO();
                List <ReviewAnswerDTO> reviewAnswers  = new List <ReviewAnswerDTO>();

                var userQuestion = examAnswer.AnswerDetails[questionIndex];
                var questionInDb = questionRepository.GetById(userQuestion.QuestionId);
                if (questionInDb.Type == 3)
                {
                    reviewAnswers.Add(new ReviewAnswerDTO
                    {
                        Content = userQuestion.Content
                    });
                }
                else
                {
                    for (int answerIndex = 0; answerIndex < userQuestion.UserAnswers.Count; answerIndex++)
                    {
                        reviewAnswers.Add(new ReviewAnswerDTO
                        {
                            Content    = answerRepository.Get(userQuestion.UserAnswers[answerIndex].AnswerId).Content,
                            IsSelected = userQuestion.UserAnswers[answerIndex].IsSelected
                        });
                    }
                }


                reviewQuestion.Content       = questionInDb.Content;
                reviewQuestion.IsCorrect     = examineeService.GetQuestionState(userQuestion.QuestionId);
                reviewQuestion.ReviewAnswers = reviewAnswers;
                reviewQuestion.Type          = questionInDb.Type;
                reviewQuestion.Difficulty    = questionInDb.Difficulty;

                reviewExamDetail.ReviewQuestions.Add(reviewQuestion);
            }

            return(JsonConvert.SerializeObject(reviewExamDetail));
        }
Пример #2
0
        public ReviewExamDTO Update(ExamAnswerDTO examAnswer, Guid userId)
        {
            ReviewExamDTO mark = examineeService.CalculateMark(examAnswer, userId);

            mark.Date   = DateTime.Now.ToString("dd/MM/yyyy");
            mark.ExamId = examAnswer.ExamId;

            Score score = Get(examAnswer.ExamId, userId);

            score.Score1        = Math.Round(mark.Score, 2, MidpointRounding.AwayFromZero);
            score.Time          = mark.TimeSpent;
            score.AnswerContent = AnswerContentJSONToString(examAnswer, score.Score1, score.Time);
            scoreRepository.Update(score);
            ExamineeService.ExamineeService.QuestionState.Clear();
            return(mark);
        }
Пример #3
0
        public ReviewExamDTO CalculateMark(ExamAnswerDTO examAnswer, Guid userId)
        {
            ReviewExamDTO mark = new ReviewExamDTO();

            mark.TimeSpent = CalculateTimeSpent(examAnswer.ExamId, userId);
            int numsOfTrue = 0;

            examAnswer.AnswerDetails.ForEach(answer =>
            {
                var key = questionRepository.GetById(answer.QuestionId);
                if (key.Type == 3)
                {
                    if (answer.Content.Equals(key.Content))
                    {
                        QuestionState.Add(key.Id, true);
                        numsOfTrue++;
                    }
                }
                else
                {
                    var userAnswers = answer.UserAnswers.Where(x => x.IsSelected == true).Select(x => x.AnswerId).OrderBy(x => x).ToList();
                    var trueAnswers = answerRepository.ListByQuestionId(key.Id).Where(x => x.IsCorrect == true).Select(x => x.Id).OrderBy(x => x).ToList();
                    if (string.Join("", userAnswers).Equals(string.Join("", trueAnswers)))
                    {
                        QuestionState.Add(key.Id, true);
                        numsOfTrue++;
                    }
                }
                if (!QuestionState.ContainsKey(key.Id))
                {
                    QuestionState.Add(key.Id, false);
                }
            });
            mark.Score = Math.Round(((Double)numsOfTrue) / examRepository.Count(examAnswer.ExamId, examService.IsRandom(examAnswer.ExamId)) * 10, 2, MidpointRounding.AwayFromZero);

            return(mark);
        }