public void AddQuestion(Question q, List <string> tags) { using var ctx = new QuestionsDbContext(_connectionString); ctx.Questions.Add(q); ctx.SaveChanges(); foreach (string tag in tags) { Tag t = GetTag(tag); int tagId; if (t == null) { tagId = AddTag(tag); } else { tagId = t.TagId; } ctx.QuestionsTags.Add(new QuestionsTags { QuestionId = q.Id, TagId = tagId }); } ctx.SaveChanges(); }
public void AddLike(Likes like) { var ctx = new QuestionsDbContext(_connectionString); ctx.Likes.Add(like); ctx.SaveChanges(); }
private int AddTag(string name) { using var ctx = new QuestionsDbContext(_connectionString); var tag = new Tag { TagName = name }; ctx.Tags.Add(tag); ctx.SaveChanges(); return(tag.TagId); }
public void AddUser(string name, string email, string password) { string passwordHash = BCrypt.Net.BCrypt.HashPassword(password); using var ctx = new QuestionsDbContext(_connectionString); var user = new User { Name = name, Email = email, PasswordHash = passwordHash }; ctx.Users.Add(user); ctx.SaveChanges(); }
public void AddAnswer(Answer a) { using var ctx = new QuestionsDbContext(_connectionString); ctx.Answers.Add(a); ctx.SaveChanges(); }