public List <Question> GetAllQuestions() { using (var context = new QuizEntities()) { return(context.Questions.Include(c => c.Answers).ToList()); } }
public List <Test> GetAllTests() { using (var context = new QuizEntities()) { return(context.Tests.Include(c => c.Difficulty).ToList()); } }
public List <UserSession> GetAllUserSessions() { using (var context = new QuizEntities()) { return(context.UserSessions.Include("User").ToList()); } }
public List <Category> GetAllCategories() { using (var context = new QuizEntities()) { return(context.Categories.ToList()); } }
public UserSession GetUserSessionById(Guid id) { using (var context = new QuizEntities()) { return(context.UserSessions.Include("User").FirstOrDefault(c => c.Id == id)); } }
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()); } }
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)); } }
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)); } }
public List <Exam> GetAllExams() { using (var context = new QuizEntities()) { return(context.Exams.Include(c => c.Test).Include(c => c.User).ToList()); } }
public User GetUserById(Guid id) { using (var context = new QuizEntities()) { return(context.Users.FirstOrDefault(c => c.Id.Equals(id))); } }
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(); } }
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(); } }
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)); } }
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); } }
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(); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }