Beispiel #1
0
 public void AddQuestion(Question newQuestion)
 {
     using (var db = new QuizModel())
     {
         db.Questions.Add(newQuestion);
         db.SaveChanges();
     }
 }
Beispiel #2
0
 public void DeleteQuestion(int id)
 {
     using (var db = new QuizModel())
     {
         var question = db.Questions.Find(id);
         db.Questions.Remove(question);
         db.SaveChanges();
     }
 }
Beispiel #3
0
        public void UpdateQuestion(Question updateQuestion)
        {
            using (var db = new QuizModel())
            {
                //attach question object to the object in the db.
                db.Questions.Attach(updateQuestion);
                var entry = db.Entry(updateQuestion);
                //the Modified indicates and update
                entry.State = System.Data.Entity.EntityState.Modified;

                foreach (var answer in updateQuestion.Answers)
                {
                    var answerEntry = db.Entry(answer);
                    answerEntry.State = System.Data.Entity.EntityState.Modified;
                }

                db.SaveChanges();
            }
        }