Ejemplo n.º 1
0
        private Questionnaire MapToQuestionnaireEntityForAdd(QuestionnaireCreateRequest request)
        {
            var questionnaire = new Questionnaire
            {
                ServiceCategoryId = request.ServiceCategoryId,
                QuestionnaireName = request.QuestionnaireName.Trim(),
                Status            = request.Status
            };

            if (request.Questions != null)
            {
                questionnaire.Questions = new List <Question>();
                foreach (var question in request.Questions)
                {
                    questionnaire.Questions.Add(new Question()
                    {
                        QuestionType = question.QuestionType,
                        QuestionTxt  = question.Question,
                        IsRequired   = question.IsRequired,
                        Options      = JsonConvert.SerializeObject(question.Options),
                    });
                }
            }

            return(questionnaire);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> AddQuestionnaire(QuestionnaireCreateRequest request)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }
                var questionnaire = MapToQuestionnaireEntityForAdd(request);
                if (await _questionnaireManager.IsQuestionnaireAlreadyExists(questionnaire, false))
                {
                    return(BadRequest("Questionnaire with this name already exists."));
                }

                if (await _questionnaireManager.IsQuestionnaireWithCategoryAlreadyExists(questionnaire, false))
                {
                    return(BadRequest("Questionnaire with this service category already exists."));
                }
                var result = await _questionnaireManager.AddQuestionnaire(questionnaire);

                if (!result)
                {
                    return(BadRequest());
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                _logger.LogError("An error has been thrown in QuestionnaireController:AddQuestionnaire", ex);
                return(BadRequest());
            }
        }