public void AddQuestion(Question newQuestion)
 {
     using (var db = new QuizModel())
     {
         db.Questions.Add(newQuestion);
         db.SaveChanges();
     }
 }
 public void DeleteQuestion(int id)
 {
     using (var db = new QuizModel())
     {
         var question = db.Questions.Find(id);
         db.Questions.Remove(question);
         db.SaveChanges();
     }
 }
 public void UpdateQuestion(Question updateQuestion)
 {
     using (var db = new QuizModel())
     {
         db.Questions.Attach(updateQuestion);
         var entry = db.Entry(updateQuestion);
         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();
     }
 }