Beispiel #1
0
 public void Create(User user)
 {
     try
     {
         user.CreatedDate = DateTime.Now.ToShortDateString();
         db.User.Add(user);
         db.SaveChanges();
     }
     catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
     {
         Exception raise = dbEx;
         foreach (var validationErrors in dbEx.EntityValidationErrors)
         {
             foreach (var validationError in validationErrors.ValidationErrors)
             {
                 string message = string.Format("{0}:{1}",
                                                validationErrors.Entry.Entity.ToString(),
                                                validationError.ErrorMessage);
                 // raise a new exception nesting
                 // the current instance as InnerException
                 raise = new InvalidOperationException(message, raise);
             }
         }
         throw raise;
     }
 }
 public int InsertQuestion(Questions question)
 {
     question.CreateTime = DateTime.Now.ToString();
     db.Questions.Add(question);
     db.SaveChanges();
     return(question.QuestionId);
 }
        public int CreateNewTest(Test test) //To create new test
        {
            test.CreatedTime = DateTime.Now.ToString();
            db.Tests.Add(test);
            db.SaveChanges();
            int id = test.TestId;

            return(id);
        }
Beispiel #4
0
 public void InsertAnswer(Answer answer)
 {
     db.Answers.Add(answer);
     db.SaveChanges();
 }
 public void InsertQuestion(Questions question)
 {
     assessmentDbContext.Questions.Add(question);
     assessmentDbContext.SaveChanges();
 }
 public void CreateNewTest(Test test) //To create new test
 {
     db.Tests.Add(test);
     db.SaveChanges();
 }