public List <Question> GetAllQuestions()
 {
     using (var context = new QuizEntities())
     {
         return(context.Questions.Include(c => c.Answers).ToList());
     }
 }
Beispiel #2
0
 public List <Test> GetAllTests()
 {
     using (var context = new QuizEntities())
     {
         return(context.Tests.Include(c => c.Difficulty).ToList());
     }
 }
Beispiel #3
0
 public List <UserSession> GetAllUserSessions()
 {
     using (var context = new QuizEntities())
     {
         return(context.UserSessions.Include("User").ToList());
     }
 }
Beispiel #4
0
 public List <Category> GetAllCategories()
 {
     using (var context = new QuizEntities())
     {
         return(context.Categories.ToList());
     }
 }
Beispiel #5
0
 public UserSession GetUserSessionById(Guid id)
 {
     using (var context = new QuizEntities())
     {
         return(context.UserSessions.Include("User").FirstOrDefault(c => c.Id == id));
     }
 }
Beispiel #6
0
 public Test GetTestById(int id)
 {
     using (var context = new QuizEntities())
     {
         return(context.Tests.Include(c => c.Difficulty).FirstOrDefault(c => c.Id == id));
     }
 }
 public User GetUserByUsername(string username)
 {
     using (var context = new QuizEntities())
     {
         return(context.Users.FirstOrDefault(c => c.Email == username));
     }
 }
 public List <QuestionType> GetAllQuestionTypes()
 {
     using (var context = new QuizEntities())
     {
         return(context.QuestionTypes.ToList());
     }
 }
 public List <User> GetAllUsers()
 {
     using (var context = new QuizEntities())
     {
         return(context.Users.Include(c => c.UserSessions).Include(c => c.Exams.Select(e => e.Test)).ToList());
     }
 }
 public List <Difficulty> GetDifficultyLevelList()
 {
     using (var context = new QuizEntities())
     {
         return(context.Difficulties.ToList());
     }
 }
Beispiel #11
0
 public Exam GetExamByUserId(Guid userId)
 {
     using (var context = new QuizEntities())
     {
         return(context.Exams.Include(c => c.Test).Include(c => c.User).FirstOrDefault(c => c.UserID == userId));
     }
 }
Beispiel #12
0
 public Exam GetExamById(int id)
 {
     using (var context = new QuizEntities())
     {
         return(context.Exams.Include(c => c.Test).Include(c => c.User).FirstOrDefault(c => c.Id == id));
     }
 }
Beispiel #13
0
 public List <Exam> GetAllExams()
 {
     using (var context = new QuizEntities())
     {
         return(context.Exams.Include(c => c.Test).Include(c => c.User).ToList());
     }
 }
Beispiel #14
0
 public User GetUserById(Guid id)
 {
     using (var context = new QuizEntities())
     {
         return(context.Users.FirstOrDefault(c => c.Id.Equals(id)));
     }
 }
Beispiel #15
0
 public void DeleteCategory(int id)
 {
     using (var context = new QuizEntities())
     {
         var category = context.Categories.FirstOrDefault(c => c.Id == id);
         context.Categories.Remove(category);
         context.SaveChanges();
     }
 }
Beispiel #16
0
 public void StartTimerById(int id)
 {
     using (var context = new QuizEntities())
     {
         var exam = context.Exams.FirstOrDefault(c => c.Id == id);
         exam.StartTime = DateTime.Now;
         context.SaveChanges();
     }
 }
Beispiel #17
0
 public Test GetTestWithQuestionsById(int id)
 {
     using (var context = new QuizEntities())
     {
         return(context.Tests.Include(c => c.Questions).
                Include(c => c.Questions.Select(q => q.Category)).
                Include(c => c.Questions.Select(q => q.Difficulty)).
                Include(c => c.Questions.Select(q => q.Answers)).FirstOrDefault(f => f.Id == id));
     }
 }
Beispiel #18
0
 public User DeleteUser(Guid id)
 {
     using (var context = new QuizEntities())
     {
         var user        = context.Users.FirstOrDefault(c => c.Id == id);
         var deletedUser = context.Users.Remove(user);
         context.SaveChanges();
         return(deletedUser);
     }
 }
Beispiel #19
0
 public Exam UpdateUserTest(Guid userId, int testId)
 {
     using (var context = new QuizEntities())
     {
         var exam = context.Exams.FirstOrDefault(c => c.UserID == userId && String.IsNullOrEmpty(c.Grade));
         exam.TestID = testId;
         context.SaveChanges();
         return(exam);
     }
 }
        public void DeleteDifficultyLevel(int id)
        {
            using (var context = new QuizEntities())
            {
                var difficulty = context.Difficulties.FirstOrDefault(c => c.Id == id);

                context.Difficulties.Remove(difficulty);

                context.SaveChanges();
            }
        }
Beispiel #21
0
 public Category AddCategory(string name)
 {
     using (var context = new QuizEntities())
     {
         var category = new Category()
         {
             Name = name
         };
         var savedCategory = context.Categories.Add(category);
         context.SaveChanges();
         return(savedCategory);
     }
 }
Beispiel #22
0
 public Exam AssignTestToUser(Guid userId, int testId)
 {
     using (var context = new QuizEntities())
     {
         var exam = new Exam()
         {
             UserID = userId,
             TestID = testId,
         };
         var savedExam = context.Exams.Add(exam);
         context.SaveChanges();
         return(savedExam);
     }
 }
        public TestsWithQuestion AddTestWithQuestion(int testId, int questionId)
        {
            using (var context = new QuizEntities())
            {
                var testWithQuestion = new TestsWithQuestion()
                {
                    TestID     = testId,
                    QuestionID = questionId
                };

                // var rez = context.TestsWithQuestions.Add(testWithQuestion);
                context.SaveChanges();
                return(new TestsWithQuestion());
            }
        }
        public Difficulty AddDifficultyLevel(string name)
        {
            using (var context = new QuizEntities())
            {
                var difficulty = new Difficulty()
                {
                    DifficultyLevel = name
                };

                var savedDifficulty = context.Difficulties.Add(difficulty);
                context.SaveChanges();

                return(savedDifficulty);
            }
        }
Beispiel #25
0
        public void AddUserSession(Guid userId)
        {
            using (var context = new QuizEntities())
            {
                var userSession = new UserSession()
                {
                    Id       = Guid.NewGuid(),
                    UserID   = userId,
                    IsValid  = true,
                    LoggedIn = DateTime.Now
                };

                context.UserSessions.Add(userSession);
                context.SaveChanges();
            }
        }
        public Answer AddAnswer(string text, bool value, int questionId)
        {
            using (var context = new QuizEntities())
            {
                var answer = new Answer()
                {
                    AnswerText = text,
                    IsCorrect  = value,
                    QuestionID = questionId
                };

                var rez = context.Answers.Add(answer);
                context.SaveChanges();

                return(rez);
            }
        }
Beispiel #27
0
 public User AddUser(Guid id, string email, Guid salt, string password, bool isAdmin)
 {
     using (var context = new QuizEntities())
     {
         var user = new User()
         {
             Id       = id,
             Email    = email,
             Salt     = salt,
             IsAdmin  = isAdmin,
             Password = password
         };
         context.Users.Add(user);
         context.SaveChanges();
         return(user);
     }
 }
Beispiel #28
0
        public UserSession SetSessionInvalid(Guid authorization)
        {
            using (var context = new QuizEntities())
            {
                var userSession = context.UserSessions.FirstOrDefault(c => c.Id == authorization && c.IsValid);

                if (userSession == null)
                {
                    return(null);
                }

                userSession.LoggedOut = DateTime.Now;
                userSession.IsValid   = false;
                context.SaveChanges();
                return(userSession);
            }
        }
Beispiel #29
0
        public Test AddTest(string name, int difficultyId, TimeSpan?duration)
        {
            using (var context = new QuizEntities())
            {
                var test = new Test()
                {
                    Name         = name,
                    DifficultyID = difficultyId,
                    Duration     = duration
                };

                var rez = context.Tests.Add(test);
                context.SaveChanges();

                return(rez);
            }
        }
        public Question AddQueston(string text, int difficultyId, int categoryId, int typeId)
        {
            using (var context = new QuizEntities())
            {
                var question = new Question()
                {
                    QuestionText = text,
                    DifficultyId = difficultyId,
                    CategoryId   = categoryId,
                    TypeId       = typeId
                };

                var rez = context.Questions.Add(question);
                context.SaveChanges();

                return(rez);
            }
        }