private PassedQuestionResult GetQuestionStatus(AnswerOnTestQuestion answer)
        {
            if (!answer.Time.HasValue)
            {
                return PassedQuestionResult.NotPassed;
            }

            return answer.Points > 0
                ? PassedQuestionResult.Success
                : PassedQuestionResult.Error;
        }
 private void SaveAnswerOnTestQuestion(AnswerOnTestQuestion answerOnTestQuestion)
 {
     using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
     {
         repositoriesContainer.RepositoryFor<AnswerOnTestQuestion>().Save(answerOnTestQuestion);
         repositoriesContainer.ApplyChanges();
     }
 }
        private void ProcessOneVariantAnswer(IEnumerable<Answer> userAnswers, Question question, AnswerOnTestQuestion answerOntestQuestion)
        {
            if (userAnswers.Count(answer => answer.СorrectnessIndicator > 0) != 1)
            {
                throw new InvalidDataException("Пользователь должен указать 1 правильный ответ");
            }

            Answer correctAnswer = question.Answers.Single(answer => answer.СorrectnessIndicator > 0);

            if (correctAnswer.Id == userAnswers.Single(answer => answer.СorrectnessIndicator > 0).Id)
            {
                answerOntestQuestion.Points = question.ComlexityLevel;
            }
        }
        private void ProcessManyVariantsAnswer(IEnumerable<Answer> userAnswers, Question question, AnswerOnTestQuestion answerOntestQuestion)
        {
            if (userAnswers.Count(answer => answer.СorrectnessIndicator > 0) == 0)
            {
                throw new InvalidDataException("Пользователь должен указать хотя бы 1 правильный ответ");
            }

            IEnumerable<Answer> correctAnswers = question.Answers.Where(answer => answer.СorrectnessIndicator > 0);

            bool isCorrect = true;
            foreach (var correctAnswer in correctAnswers)
            {
                isCorrect = isCorrect && userAnswers
                    .Where(answer => answer.СorrectnessIndicator > 0)
                    .Any(userAnswer => userAnswer.Id == correctAnswer.Id);
            }

            isCorrect = isCorrect && userAnswers.Count(answer => answer.СorrectnessIndicator > 0) == correctAnswers.Count();

            if (isCorrect)
            {
                answerOntestQuestion.Points = question.ComlexityLevel;
            }
        }
        private void ProcessTextAnswer(IEnumerable<Answer> userAnswers, Question question, AnswerOnTestQuestion answerOntestQuestion)
        {
            if (userAnswers.Count() != 1)
            {
                throw new InvalidDataException("Пользователь должен указать 1 правильный ответ");
            }

            if (userAnswers.Single().Content == null)
            {
                throw new InvalidDataException("Пользователь должен указать ответ");
            }

            if (question.Answers.Select(answer => answer.Content.ToLower()).Contains(userAnswers.Single().Content.ToLower()))
            {
                answerOntestQuestion.Points = question.ComlexityLevel;
            }
        }
        private void ProcessSequenceAnswer(List<Answer> answers, Question question, AnswerOnTestQuestion answerOntestQuestion)
        {
            bool isCorrect = true;
            if (answers.Count() != question.Answers.Count)
            {
                throw new InvalidDataException("Последовательность не совпадает с исходной");
            }

            var plainAnswers = question.Answers.ToList();
            for (int i = 0; i < answers.Count(); i++)
            {
                isCorrect = isCorrect && answers[i].Id == plainAnswers[i].Id;
            }

            if (isCorrect)
            {
                answerOntestQuestion.Points = question.ComlexityLevel;
            }
        }