Exemple #1
0
 public void AddUser(User user)
 {
     using (var context = new StackContext(_connectionString))
     {
         context.Users.Add(user);
         context.SaveChanges();
     }
 }
Exemple #2
0
 public void AddAnswer(Answer answer)
 {
     using (var context = new StackContext(_connectionString))
     {
         context.Answers.Add(answer);
         context.SaveChanges();
     }
 }
Exemple #3
0
 public void AddQuestion(Question question)
 {
     using (var context = new StackContext(_connectionString))
     {
         context.Questions.Add(question);
         context.SaveChanges();
     }
 }
Exemple #4
0
 public Tag AddTag(Tag tag)
 {
     using (var context = new StackContext(_connectionString))
     {
         context.Tags.Add(tag);
         context.SaveChanges();
         return(tag);
     }
 }
Exemple #5
0
 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());
     }
 }
Exemple #6
0
 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());
     }
 }
Exemple #7
0
        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();
                }
            }
        }