Пример #1
0
        public Survey Add(Survey survey)
        {
            using (var dbContextTransaction = _context.Database.BeginTransaction())
            {
                try
                {
                    foreach (var answerGroup in survey.AnswerGroup)
                    {
                        _context.Address.Add(answerGroup.Address);
                        _context.SaveChanges();
                        answerGroup.AddressId = answerGroup.Address.Id;
                    }
                    _context.Survey.Add(survey);
                    _context.SaveChanges();

                    dbContextTransaction.Commit();
                    //todo get the id
                    //possibly add newAnswerGroups to the survey
                }
                catch (Exception ex)
                {
                    dbContextTransaction.Rollback();
                    throw;
                }
                return(survey);
            }
        }
Пример #2
0
 public OptionGroup Add(OptionGroup optionGroup)
 {
     using (var dbContextTransaction = _context.Database.BeginTransaction())
     {
         try
         {
             _context.OptionGroup.Add(optionGroup);
             _context.SaveChanges();
             dbContextTransaction.Commit();
         }
         catch (Exception ex)
         {
             dbContextTransaction.Rollback();
         }
         return(optionGroup);
     }
 }
 public QuestionType Add(QuestionType questionType)
 {
     using (var dbContextTransaction = _context.Database.BeginTransaction())
     {
         try
         {
             _context.QuestionType.Add(questionType);
             _context.SaveChanges();
             dbContextTransaction.Commit();
         }
         catch (Exception ex)
         {
             dbContextTransaction.Rollback();
         }
         return(questionType);
     }
 }
Пример #4
0
 public AnswerSection Add(AnswerSection answerSection)
 {
     using (var dbContextTransaction = _context.Database.BeginTransaction())
     {
         try
         {
             _context.AnswerSection.Add(answerSection);
             _context.SaveChanges();
             dbContextTransaction.Commit();
         }
         catch (Exception ex)
         {
             dbContextTransaction.Rollback();
             throw;
         }
         return(answerSection);
     }
 }
Пример #5
0
 public AnswerGroup Add(AnswerGroup answerGroup)
 {
     using (var dbContextTransaction = _context.Database.BeginTransaction())
     {
         try
         {
             var address = _context.Address.Add(answerGroup.Address);
             answerGroup.AddressId = address.Entity.Id;
             _context.AnswerGroup.Add(answerGroup);
             _context.SaveChanges();
             dbContextTransaction.Commit();
         }
         catch (Exception ex)
         {
             dbContextTransaction.Rollback();
         }
         return(answerGroup);
     }
 }
 public Customer Add(Customer customer)
 {
     _context.Customer.Add(customer);
     _context.SaveChanges();
     return(customer);
 }
Пример #7
0
 public Comment Add(Comment comment)
 {
     _context.Comment.Add(comment);
     _context.SaveChanges();
     return(comment);
 }