Beispiel #1
0
 public List <Grade> GetUserGradeFromQuizNameAndUserId(string quizName, int userId)
 {
     using (var db = new QuizDatabase())
     {
         return(db.Grades.Include("Quiz").Include("User").Where(g => g.Quiz.Name == quizName).Where(g => g.UserId == userId).ToList());
     }
 }
Beispiel #2
0
 public ObservableCollection <Quiz> GetQuizzes()
 {
     using (var db = new QuizDatabase())
     {
         return(new ObservableCollection <Quiz>(db.Quizs.ToList()));
     }
 }
Beispiel #3
0
 public List <User> GetStudentName()
 {
     using (var db = new QuizDatabase())
     {
         return(db.Users.ToList());
     }
 }
Beispiel #4
0
 public bool DoesGradeExcist(int quizId, int userId)
 {
     using (var db = new QuizDatabase())
     {
         return(db.Grades.Any(g => g.QuizId == SelectedQuizId && g.UserId == LoggedInUserId));
     }
 }
Beispiel #5
0
 public List <Quiz> GetQuizName()
 {
     using (var db = new QuizDatabase())
     {
         return(db.Quizs.ToList());
     }
 }
Beispiel #6
0
 public List <Question> GetQuestionsForQuiz(int quizId)
 {
     using (var db = new QuizDatabase())
     {
         return(db.Questions.Where(q => q.QuizId == quizId).ToList());
     }
 }
Beispiel #7
0
 public ObservableCollection <Grade> GetUserGrade(int userId)
 {
     using (var db = new QuizDatabase())
     {
         return(new ObservableCollection <Grade>(db.Grades.Include("Quiz").Include("User").Where(g => g.UserId == userId)));
     }
 }
Beispiel #8
0
 public bool CheckEmailExicts(string email)
 {
     using (QuizDatabase db = new QuizDatabase())
     {
         return(db.Users.Any(u => u.Email == email));
     }
 }
Beispiel #9
0
 public User CheckEmail(string email)
 {
     using (QuizDatabase db = new QuizDatabase())
     {
         return(db.Users.FirstOrDefault(u => u.Email == email));
     }
 }
Beispiel #10
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 #11
0
 public void AddUser(User user)
 {
     using (QuizDatabase db = new QuizDatabase())
     {
         db.Users.Add(user);
         db.SaveChanges();
     }
 }
Beispiel #12
0
 public void SaveUserQuizScore(Grade userGrade)
 {
     using (var db = new QuizDatabase())
     {
         db.Grades.Add(userGrade);
         db.SaveChanges();
     }
 }
Beispiel #13
0
 public List <Grade> GetUserGradeFromQuizName(string quizName)
 {
     using (var db = new QuizDatabase())
     {
         List <Grade> temp = db.Grades.Include("Quiz").Include("User").Where(g => g.Quiz.Name == quizName).ToList();
         return(db.Grades.Include("Quiz").Include("User").Where(g => g.Quiz.Name == quizName).ToList());
     }
 }
Beispiel #14
0
 public void AddQuiz(Quiz quiz)
 {
     using (var db = new QuizDatabase())
     {
         db.Quizs.Add(quiz);
         db.SaveChanges();
     }
 }
Beispiel #15
0
 public void AddQuestion(Question question)
 {
     using (var db = new QuizDatabase())
     {
         db.Questions.Add(question);
         db.SaveChanges();
     }
 }
Beispiel #16
0
 public void RemoveQuiz(Quiz quiz)
 {
     using (var db = new QuizDatabase())
     {
         db.Quizs.Attach(quiz);
         db.Quizs.Remove(quiz);
         db.SaveChanges();
     }
 }
Beispiel #17
0
 public void RemoveUser(User user)
 {
     using (var db = new QuizDatabase())
     {
         db.Users.Attach(user);
         db.Users.Remove(user);
         db.SaveChanges();
     }
 }
Beispiel #18
0
 public ObservableCollection <User> GetUsers()
 {
     using (QuizDatabase db = new QuizDatabase())
     {
         foreach (var item in db.Users.ToList())
         {
             Users.Add(item);
         }
         return(Users);
     }
 }
Beispiel #19
0
        public ObservableCollection <Quiz> GetQuizForUser(int userId)
        {
            using (var db = new QuizDatabase())
            {
                List <int> quizIdsList = db.Grades.Where(g => g.UserId == userId).Select(g => g.QuizId).ToList();

                return(new ObservableCollection <Quiz>(db.Quizs.Where(q => !quizIdsList.Contains(q.Id))
                                                       .Where(q => q.CreationDate < DateTime.Now)
                                                       .Where(q => q.EndDate > DateTime.Now)
                                                       .ToList()));
            }
        }
Beispiel #20
0
        public List <Grade> GetQuizStats()
        {
            using (var db = new QuizDatabase())
            {
                List <Grade> Grades = new List <Grade>();

                Grades = db.Grades.Include("Quiz").Include("User")
                         .OrderBy(g => g.Quiz.Id)
                         .ToList();

                return(Grades);
            }
        }