Example #1
0
        private void SetAnswer(StudentTestSessionQuestion question, QuestionGenericAnswer answer)
        {
            switch (question.Question.Type)
            {
            case QuestionType.FreeText:
                SetFreeTextAnswer(question, answer.FreeTextAnswer);
                return;

            case QuestionType.QuestionWithChoice:
                SetChoiceQuestionAnswer(question, answer.ChoiceQuestionAnswer);
                return;

            default:
                throw new InvalidEnumArgumentException(
                          nameof(question.Question.Type),
                          (int)question.Question.Type,
                          typeof(QuestionType));
            }
        }
Example #2
0
        public async Task Answer(Guid questionId, QuestionGenericAnswer answer)
        {
            // TODO: add includes to optimize query
            var queryParameters = new StudentTestSessionQuestionQueryParameters
            {
                StudentId  = _executionContextService.GetCurrentUserId(),
                IsReadOnly = false,
                Id         = questionId,
            };
            StudentTestSessionQuestion question = await _unitOfWork.GetSingle(queryParameters);

            await _studentQuestionValidationService.ThrowIfCannotAnswer(question.StudentTestSessionId);

            SetAnswer(question, answer);

            await _unitOfWork.Update(question);

            await _unitOfWork.Commit();
        }