public Question GetQuestionForId(int questionId) { using (var context = new StackOverflowContext(_connectionString)) { return(context.Questions.FirstOrDefault(q => q.Id == questionId)); } }
public List <Question> GetQuestions() { using (var context = new StackOverflowContext(_connectionString)) { return(context.Questions.OrderByDescending(q => q.DatePosted).ToList()); } }
public void PostLike(Like like) { using (var context = new StackOverflowContext(_connectionString)) { context.Likes.Add(like); context.SaveChanges(); } }
public void PostAnswer(Answer answer) { using (var context = new StackOverflowContext(_connectionString)) { context.Answers.Add(answer); context.SaveChanges(); } }
public void PostQuestion(Question question) { using (var context = new StackOverflowContext(_connectionString)) { context.Questions.Add(question); context.SaveChanges(); } }
public List <Answer> GetAnswersForId(int questionId) { using (var context = new StackOverflowContext(_connectionString)) { List <Answer> answers = context.Answers.Where(a => a.QuestionId == questionId).ToList(); return(answers); } }
public bool GetUserLiked(int questionId, int userId) { using (var context = new StackOverflowContext(_connectionString)) { bool userLiked = context.Likes.Any(l => l.QuestionId == questionId && l.UserId == userId); return(userLiked); } }
public int GetNumberOfLikes(int questionId) { using (var context = new StackOverflowContext(_connectionString)) { int numberOfLikes = context.Likes.Where(l => l.QuestionId == questionId).ToList().Count(); return(numberOfLikes); } }
public void AddUser(User user) { user.Password = BCrypt.Net.BCrypt.HashPassword(user.Password); using (var context = new StackOverflowContext(_connectionString)) { context.Users.Add(user); context.SaveChanges(); } }
public int GetIdForEmail(string email) { int id = 0; using (var context = new StackOverflowContext(_connectionString)) { id = context.Users.FirstOrDefault(u => u.Email == email).Id; } return(id); }
public string GetPasswordForEmail(string email) { string password = ""; using (var context = new StackOverflowContext(_connectionString)) { password = context.Users.FirstOrDefault(u => u.Email == email).Password; } return(password); }
public List <Tag> GetTagsForId(int questionId) { using (var context = new StackOverflowContext(_connectionString)) { List <Tag> tags = context.Tags.FromSql(@"SELECT T.Id, T.Name FROM Tags T JOIN QuestionsTags QT ON T.Id=QT.TagId WHERE QuestionId=@questionId" , new SqlParameter("@questionid", questionId)).ToList(); return(tags); } }
public UnitOfWork() { _context = new StackOverflowContext(); }