예제 #1
0
 public void DeleteQuestion(int id)
 {
     using (var db = new QuizModel())
     {
         var question = db.Questions.Find(id);
         db.Questions.Remove(question);
         db.SaveChanges();
     }
 }
예제 #2
0
 public Question GetQuestionById(int id)
 {
     using (var db = new QuizModel())
     {
         var question = db.Questions.Find(id);
         db.Entry(question).Collection(q => q.Answers).Load();
         return(question);
     }
 }
예제 #3
0
 public List <Question> GetQuestions()
 {
     using (var db = new QuizModel())
     {
         var questions = from q in db.Questions
                         orderby q.QuestionId descending
                         select q;
         return(questions.ToList());
     }
 }
예제 #4
0
        public QuestionViewModel GetQuestion()
        {
            using (var db = new QuizModel())
            {
                var qList = db.Questions
                            .Include(j => j.Answers)
                            .ToList();

                return(new QuestionViewModel(qList[_randy.Next(0, qList.Count)]));
            }
        }
예제 #5
0
 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();
     }
 }