Beispiel #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);
        }
Beispiel #2
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 #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);
        }
Beispiel #4
0
        public async Task <SurveyUserModelBase> Update(SurveyUserUpdateModel model)
        {
            var entity = _mapper.Map <SurveyUser>(model);

            _context.SurveyUsers.Attach(entity);
            _context.Entry(entity).State = EntityState.Modified;

            await SaveAsync();

            return(_mapper.Map <SurveyUserModelBase>(entity));
        }
Beispiel #5
0
        public int EditSurvey(Survey survey)
        {
            dbContext.Entry(survey).State = EntityState.Modified;

            return(dbContext.SaveChanges());
        }
Beispiel #6
0
 public void Update(T entity)
 {
     _context.Entry(entity).State = EntityState.Modified;
     Save();
 }
        public int EditUser(User user)
        {
            dbContext.Entry(user).State = EntityState.Modified;

            return(dbContext.SaveChanges());
        }
Beispiel #8
0
 public virtual void Update(T entity)
 {
     DbSet.Attach(entity);
     DataContext.Entry(entity)
     .State = EntityState.Modified;
 }