Beispiel #1
0
        public StatusGenericHandler AddQuestion(string text, QuestionType type, SurveyDbContext context = null)
        {
            var status   = new StatusGenericHandler();
            var question = new Question(text, type, this);

            if (_questions != null)
            {
                _questions.Add(question);
            }
            else if (context == null)
            {
                status.AddError("You must provide a context if you want to remove this Survey.", nameof(context));
                return(status);
            }
            else if (context.Entry(this).IsKeySet)
            {
                context.Add(new Question(text, type, this));
            }
            else
            {
                status.AddError("Could not add a new survey.", nameof(context));
                return(status);
            }

            return(status);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public StatusGenericHandler AddQuestion(CompletedQuestion question, SurveyDbContext context = null)
        {
            var status = new StatusGenericHandler();

            if (string.IsNullOrWhiteSpace(question.Answer))
            {
                status.AddError("An answer is needed when submitting a question.", nameof(question.Answer));
                return(status);
            }

            if (_completedQuestions != null)
            {
                var completedQuestion = new CompletedQuestion(question.Question, question.Answer, this);
                _completedQuestions.Add(completedQuestion);
            }
            else if (context == null)
            {
                status.AddError("You must provide a context if the CompletedQuestions collection isn't valid.", nameof(context));
                return(status);
            }
            else if (context.Entry(this).IsKeySet)
            {
                context.Add(new CompletedQuestion(question.Question, question.Answer, this));
            }
            else
            {
                status.AddError("Could not add a new CompletedQuestion.");
                return(status);
            }

            return(status);
        }
        public IImmutableList <ValidationResult> AddSurvey(SurveyDto surveyDto)
        {
            if (surveyDto.QuestionGroupsDtos == null)
            {
                Status.AddError("No question groups have been submitted with this survey.");
                return(Status.Errors);
            }

            if (string.IsNullOrWhiteSpace(surveyDto.Name))
            {
                Status.AddError("A name has not been provided for this survey.");
                return(Status.Errors);
            }

            var questionGroups = _questionMapper.Map(surveyDto.QuestionGroupsDtos, _context);
            var survey         = new Survey(surveyDto.Name, questionGroups);

            if (Status.HasErrors)
            {
                return(Status.Errors);
            }

            _context.Add(survey);
            _context.SaveChanges();
            return(null);
        }
Beispiel #5
0
 public void Create(T entity)
 {
     _context.Add(entity);
     Save();
 }