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 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 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 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 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 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); } }