Beispiel #1
0
 public Quiz CreateQuiz(Quiz quiz)
 {
     var ctx = QuizlrContext.Current;
     ctx.Quizzes.Add(quiz);
     ctx.SaveChanges();
     return quiz;
 }
Beispiel #2
0
 public void UpdateQuiz(Quiz quiz)
 {
     var ctx = QuizlrContext.Current;
     ctx.Quizzes.Attach(quiz);
     ctx.Entry(quiz).State = EntityState.Modified;
     ctx.SaveChanges();
 }
Beispiel #3
0
 public static Quiz Generate()
 {
     var category = new Category {CategoryId = 1, Name = "FooBar"};
     var quiz = new Quiz {QuizId = 1, Name = "FooBar"};
     var questions = new List<Question>
     {
         new Question
         {
             QuestionId = 1,
             Text = "Foo",
             Category = category,
             Answers = new List<Answer>
             {
                 new Answer {AnswerId = 1, Text = "Foo", IsCorrect = true},
                 new Answer {AnswerId = 2, Text = "Bar", IsCorrect = false}
             }
         },
         new Question
         {
             QuestionId = 2,
             Text = "Bar",
             Category = category,
             Answers = new List<Answer>
             {
                 new Answer {AnswerId = 3, Text = "Foo", IsCorrect = true},
                 new Answer {AnswerId = 4, Text = "Bar", IsCorrect = false}
             }
         }
     };
     var quizQuestions = new List<QuizQuestion>();
     foreach (var question in questions)
     {
         var quizQuestion = new QuizQuestion
         {
             QuizId = quiz.QuizId,
             Quiz = quiz,
             QuestionId = question.QuestionId,
             Question = question
         };
         question.QuizQuestions = quizQuestions;
         quizQuestions.Add(quizQuestion);
     }
     quiz.QuizQuestions = quizQuestions;
     return quiz;
 }
Beispiel #4
0
 public void DeleteQuiz(Quiz quiz)
 {
     var ctx = QuizlrContext.Current;
     ctx.Quizzes.Remove(quiz);
     ctx.SaveChanges();
 }