Beispiel #1
0
        public Repository()
        {
            WriteLine("Does database excist?");

            using (QuizDatabase db = new QuizDatabase())
            {
                bool wasDbCreated = db.Database.CreateIfNotExists();
                WriteLine(wasDbCreated ? "Database was created" : "Database already excists");
            }
            WriteLine("All done");

            using (var db = new QuizDatabase())
            {
                if (!db.Users.Any(u => u.Email == "*****@*****.**"))
                {
                    var user = new User()
                    {
                        FirstName = "Admin",
                        LastName  = "Adminsson",
                        Email     = "*****@*****.**",
                        Password  = "******",
                        IsAdmin   = true
                    };
                    db.Users.Add(user);
                    db.SaveChanges();
                    Console.WriteLine("[email protected] added");
                }
            }
        }
Beispiel #2
0
 public void AddQuestion(Question question)
 {
     using (var db = new QuizDatabase())
     {
         db.Questions.Add(question);
         db.SaveChanges();
     }
 }
Beispiel #3
0
 public void AddQuiz(Quiz quiz)
 {
     using (var db = new QuizDatabase())
     {
         db.Quizs.Add(quiz);
         db.SaveChanges();
     }
 }
Beispiel #4
0
 public void AddUser(User user)
 {
     using (QuizDatabase db = new QuizDatabase())
     {
         db.Users.Add(user);
         db.SaveChanges();
     }
 }
Beispiel #5
0
 public void SaveUserQuizScore(Grade userGrade)
 {
     using (var db = new QuizDatabase())
     {
         db.Grades.Add(userGrade);
         db.SaveChanges();
     }
 }
Beispiel #6
0
 public void RemoveQuiz(Quiz quiz)
 {
     using (var db = new QuizDatabase())
     {
         db.Quizs.Attach(quiz);
         db.Quizs.Remove(quiz);
         db.SaveChanges();
     }
 }
Beispiel #7
0
 public void RemoveUser(User user)
 {
     using (var db = new QuizDatabase())
     {
         db.Users.Attach(user);
         db.Users.Remove(user);
         db.SaveChanges();
     }
 }