public void AddQuestion(Question question, string tagString)
        {
            using (var ctx = new QuestionsContext(_connectionString))
            {
                ctx.Questions.Add(question);
                ctx.SaveChanges();
                var tags = tagString.Split(" ");
                foreach (string t in tags)
                {
                    var tag = GetTag(t);
                    if (tag == null)
                    {
                        tag = new Tag {
                            Title = t
                        };
                        AddTag(tag);
                    }

                    ctx.QuestionsTags.Add(new QuestionTag
                    {
                        QuestionId = question.Id,
                        TagId      = tag.Id
                    });
                }
                ctx.SaveChanges();
            }
        }
 public void AddTag(Tag tag)
 {
     using (var ctx = new QuestionsContext(_connectionString))
     {
         ctx.Tags.Add(tag);
         ctx.SaveChanges();
     }
 }
 public void AddAnswer(Answer answer)
 {
     using (var ctx = new QuestionsContext(_connectionString))
     {
         ctx.Answers.Add(answer);
         ctx.SaveChanges();
     }
 }
        public void AddUser(User user, string password)
        {
            var passwordHash = BCrypt.Net.BCrypt.HashPassword(password);

            user.PasswordHash = passwordHash;

            using (var ctx = new QuestionsContext(_connectionString))
            {
                ctx.Users.Add(user);
                ctx.SaveChanges();
            }
        }
 public void AddLike(Like like)
 {
     using (var ctx = new QuestionsContext(_connectionString))
     {
         ctx.Likes.Add(new Like
         {
             QuestionId = like.QuestionId,
             UserId     = like.UserId
         });
         ctx.SaveChanges();
     }
 }