Ejemplo n.º 1
0
        public async Task <IActionResult> GetQuestionAsync([FromRoute] string questionId)
        {
            var question = await readContext.SurveyQuestionBank
                           .FindAsync(questionId);

            if (question == null)
            {
                return(NotFound());
            }

            var dto = new QuestionDto
            {
                UID             = question.UID,
                QuestionId      = question.IdQuestion,
                QuestionText    = question.DsQuestion,
                CodeType        = question.CdCodeType,
                QuestionType    = question.CdQuestionType,
                SaveToBank      = question.InBankQuestion,
                HasBeenAnswered = question.InAnswered
            };

            if (!string.IsNullOrWhiteSpace(question.CdCodeType))
            {
                dto.Choices = await codes.GetCodes(question.CdCodeType);
            }

            return(Ok(dto));
        }
Ejemplo n.º 2
0
        private async Task LoadCurrentQuestionInfo(IEnumerable <LayoutItemDto> items, IEnumerable <SurveyQuestionBank> questions)
        {
            foreach (var item in items)
            {
                if (item.Type == LayoutItemType.Question)
                {
                    var question = questions.FirstOrDefault(q => q.IdQuestion == item.Id);

                    if (question == null)
                    {
                        throw new EntityNotFoundException(typeof(SurveyQuestionBank), item.Id);
                    }

                    item.Text         = question.DsQuestion;
                    item.QuestionType = question.CdQuestionType;

                    if (!string.IsNullOrWhiteSpace(question.CdCodeType))
                    {
                        item.Choices = await codeRepos.GetCodes(question.CdCodeType);
                    }
                }

                await LoadCurrentQuestionInfo(item.Items, questions);
            }
        }
Ejemplo n.º 3
0
        public SurveyAnswerRules AnswersAreCorrect()
        {
            Rule(async command =>
            {
                SurveyAnswerBindingHelpers.Bind(command.Answers);

                IDictionary <string, object> answers = command.Answers;

                foreach (var questionId in answers.Keys)
                {
                    if (!SurveyAnswerBindingHelpers.IsQuestion(questionId))
                    {
                        //skip validating the control types
                        continue;
                    }

                    var questionBank = await readContext.SurveyQuestionBank
                                       .FindAsync(questionId);

                    var question = new QuestionDto
                    {
                        UID             = questionBank.UID,
                        QuestionId      = questionBank.IdQuestion,
                        QuestionText    = questionBank.DsQuestion,
                        CodeType        = questionBank.CdCodeType,
                        QuestionType    = questionBank.CdQuestionType,
                        SaveToBank      = questionBank.InBankQuestion,
                        HasBeenAnswered = questionBank.InAnswered
                    };

                    if (question == null)
                    {
                        Error($"Question with Question ID '{questionId}' was not found", "AnswerValidation");
                    }

                    var answer = command.Answers[questionId];

                    //Answers are optional no need to validate
                    if (answer == null || answer is string && string.IsNullOrWhiteSpace((string)answer))
                    {
                        continue;
                    }


                    //why does this not return a bool?
                    var response = EnsureAnswerIsCorrectDataType(question.QuestionType, answer);

                    if (response != string.Empty)
                    {
                        Error(response, questionId.ToString().ToUpper());
                    }



                    if (!string.IsNullOrWhiteSpace(question.CodeType))
                    {
                        var dropdownList = await codeRepository.GetCodes(question.CodeType);

                        var list = SurveyAnswerBindingHelpers.HasMultipleAnswers(answer) ? answer : new[] { answer };

                        foreach (var item in list)
                        {
                            if (!dropdownList.Any(code => code.Code == item))
                            {
                                Error($"Answer value '{item}' is not a valid code from code type '{question.CodeType}'", "AnswerValidation");
                            }
                        }
                    }
                }
            });

            return(this);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> GetAsync([FromRoute] string codeType)
        {
            var codes = await repos.GetCodes(codeType);

            return(Ok(codes));
        }