Example #1
0
        public AssessmentStatusEnum SetAssessmentNextStep(Guid assessmentId, Guid questionOptionId, string furtherInformation)
        {
            var assessment = _assessmentHelper.GetAssessment(assessmentId);

            var workflowStep = _workflowStepHelper.GetWorkflowStep(questionOptionId, assessment);

            if (workflowStep == null)
            {
                throw new WorkflowStepNotFoundException();
            }

            if (!assessment.ReadOnly)
            {
                var questionAnswer = _questionAnswerHelper.GetQuestionAnswer(assessment);

                if (HasAnsweredPreviously(questionAnswer))
                {
                    _questionAnswerHelper.RemoveQuestionAnswer(questionAnswer);
                }

                _questionAnswerHelper.AddQuestionAnswer(questionOptionId, furtherInformation, assessment);
            }

            if (HasNextStep(workflowStep))
            {
                var resetQuestionId = assessment.ResetWorkflowQuestionId;

                if (assessment.ReadOnly && HasProgressesedToRestartQuestion(assessment, workflowStep))
                {
                    _assessmentHelper.UpdateAssessmentReadonly(assessmentId, false);
                    resetQuestionId = null;
                }

                _assessmentHelper.UpdateAssessmentQuestions(assessmentId, workflowStep.NextWorkflowQuestionId.Value, assessment.CurrentWorkflowQuestionId, resetQuestionId);
            }

            _assessmentHelper.UpdateAssessmentStatus(assessmentId, (AssessmentStatusEnum)workflowStep.OutcomeStatusId);

            SaveChanges();

            return((AssessmentStatusEnum)workflowStep.OutcomeStatusId);
        }