Ejemplo n.º 1
0
        private StatusGenericHandler AddQuestionGroup(string name, IEnumerable <Question> questions, SurveyDbContext context = null)
        {
            var status = new StatusGenericHandler();

            if (string.IsNullOrWhiteSpace(name))
            {
                status.AddError("A name is needed when creating a new question group.", nameof(name));
                return(status);
            }

            if (_questionGroups != null)
            {
                var questionGroup = new QuestionGroup(name, questions, this);
                _questionGroups.Add(questionGroup);
            }
            else if (context == null)
            {
                status.AddError("You must provide a context if the QuestionGroups collection isn't valid.", nameof(context));
                return(status);
            }
            else if (context.Entry(this).IsKeySet)
            {
                context.Add(new QuestionGroup(name, questions, this));
            }
            else
            {
                status.AddError("Could not add a new QuestionGroup.");
                return(status);
            }

            return(status);
        }
Ejemplo n.º 2
0
        public StatusGenericHandler AddQuestions(IEnumerable <Question> questions, QuestionGroup questionGroup, SurveyDbContext context = null)
        {
            var status = new StatusGenericHandler();

            if (questions == null)
            {
                status.AddError("No Questions have been provided", nameof(questions));
                return(status);
            }

            foreach (var question in questions)
            {
                status = AddQuestion(question.Text, question.QuestionType, questionGroup, context);
            }
            return(status);
        }
Ejemplo n.º 3
0
        private StatusGenericHandler AddQuestion(string text, QuestionType questionType, QuestionGroup questionGroup, SurveyDbContext context = null)
        {
            var status = new StatusGenericHandler();


            if (string.IsNullOrWhiteSpace(text))
            {
                status.AddError("Question text is needed when creating a new question.", nameof(text));
                return(status);
            }

            if (questionType == null)
            {
                status.AddError("A QuestionType has not been specified.", nameof(questionType));
                return(status);
            }
            if (questionGroup == null)
            {
                status.AddError("A QuestionGroup which to add this question to has not been specified.", nameof(questionGroup));
                return(status);
            }
            if (context != null)
            {
                status = questionGroup.AddQuestion(text, questionType, context);
            }
            else
            {
                status.AddError("Could not add a new Question.");
                return(status);
            }

            return(status);
        }