public void AddUser(User user) { using (var context = new StackContext(_connectionString)) { context.Users.Add(user); context.SaveChanges(); } }
public void AddAnswer(Answer answer) { using (var context = new StackContext(_connectionString)) { context.Answers.Add(answer); context.SaveChanges(); } }
public void AddQuestion(Question question) { using (var context = new StackContext(_connectionString)) { context.Questions.Add(question); context.SaveChanges(); } }
public Tag AddTag(Tag tag) { using (var context = new StackContext(_connectionString)) { context.Tags.Add(tag); context.SaveChanges(); return(tag); } }
public int AddLikedAnswers(int answerId, int userId) { using (var context = new StackContext(_connectionString)) { if (context.LikedAnswers.Any(l => l.UserId == userId && l.AnswerId == answerId)) { return(context.LikedAnswers.Where(l => l.AnswerId == answerId).ToList().Count()); } context.LikedAnswers.Add(new LikedAnswers { AnswerId = answerId, UserId = userId }); context.SaveChanges(); return(context.LikedAnswers.Where(l => l.AnswerId == answerId).ToList().Count()); } }
public int AddLikedQuestion(int questionId, int userId) { using (var context = new StackContext(_connectionString)) { if (context.LikedQuestions.Any(l => l.QuestionId == questionId && l.UserId == userId)) { return(context.LikedQuestions.Where(l => l.QuestionId == questionId).ToList().Count()); } context.LikedQuestions.Add(new LikedQuestions { QuestionId = questionId, UserId = userId }); context.SaveChanges(); return(context.LikedQuestions.Where(l => l.QuestionId == questionId).ToList().Count()); } }
public void AddQuestionTags(IEnumerable <string> tags, int questionId) { using (var context = new StackContext(_connectionString)) { foreach (string t in tags) { Tag tag = context.Tags.FirstOrDefault(ta => ta.Content == t) ?? AddTag(new Tag { Content = t }); context.QuestionsTags.Add(new QuestionsTags { QuestionId = questionId, TagId = tag.Id }); context.SaveChanges(); } } }