public void AddQuestion(Question question, List <string> tagTexts)
        {
            using var context = new QADbContext(_connectionString);
            context.Questions.Add(question);
            context.SaveChanges();
            var tags = GetTags();

            foreach (string tagText in tagTexts)
            {
                var tag = tags.FirstOrDefault(t => t.Name == tagText);
                if (tag == null)
                {
                    tag = new Tag
                    {
                        Name = tagText
                    };
                    context.Tags.Add(tag);
                }
                context.QuestionsTags.Add(new QuestionsTags
                {
                    QuestionId = question.Id,
                    Question   = question,
                    Tag        = tag,
                    TagId      = tag.Id
                });
            }
            context.SaveChanges();
        }
 public void AddUser(User user, string password)
 {
     user.PasswordHash = BCrypt.Net.BCrypt.HashPassword(password);
     using var context = new QADbContext(_connectionString);
     context.Users.Add(user);
     context.SaveChanges();
 }
        public void UpdateLikes(int id, User user)
        {
            using var context = new QADbContext(_connectionString);
            var like = new Likes
            {
                QuestionId = id,
                UserId     = user.Id
            };

            context.Likes.Add(like);
            context.SaveChanges();
        }
 public void AddAnswer(Answer answer)
 {
     using var context = new QADbContext(_connectionString);
     context.Answers.Add(answer);
     context.SaveChanges();
 }