Пример #1
0
        public void AddQuestion(Question question, IEnumerable <string> tags)
        {
            using (var ctx = new QASiteContext(_connectionString))
            {
                ctx.Questions.Add(question);
                foreach (string tag in tags)
                {
                    Tag t = GetTag(tag);
                    int tagId;
                    if (t == null)
                    {
                        tagId = AddTag(tag);
                    }
                    else
                    {
                        tagId = t.Id;
                    }
                    ctx.QuestionsTags.Add(new QuestionsTags
                    {
                        QuestionId = question.Id,
                        TagId      = tagId
                    });
                }

                ctx.SaveChanges();
            }
        }
Пример #2
0
 public void AddAnswer(Answer answer)
 {
     using (var context = new QASiteContext(_connectionString))
     {
         context.Answers.Add(answer);
         context.SaveChanges();
     }
 }
Пример #3
0
        public void AddUser(User user, string password)
        {
            user.PasswordHash = PasswordHelper.HashPassword(password);

            using (var context = new QASiteContext(_connectionString))
            {
                context.Users.Add(user);
                context.SaveChanges();
            }
        }
Пример #4
0
 private int AddTag(string name)
 {
     using (var ctx = new QASiteContext(_connectionString))
     {
         var tag = new Tag {
             Name = name
         };
         ctx.Tags.Add(tag);
         ctx.SaveChanges();
         return(tag.Id);
     }
 }
Пример #5
0
 public void AddQuestionLike(int questionId, int userId)
 {
     using (var context = new QASiteContext(_connectionString))
     {
         var like = new QuestionLike
         {
             QuestionId = questionId,
             UserId     = userId
         };
         context.QuestionLikes.Add(like);
         context.SaveChanges();
     }
 }