public void AddQuestion(Question question, List <String> tagList) { using (var context = new QuestionAnswerContext(_conn)) { question.Date = DateTime.Now; context.Questions.Add(question); context.SaveChanges(); foreach (String t in tagList) { var tag = CheckTagExists(t); if (tag == null) { Tag newtag = new Tag { Name = t }; AddTag(newtag); tag = newtag;//used to add to questiontags } context.QuestionTags.Add(new QuestionTags { QuestionId = question.Id, TagId = tag.Id }); context.SaveChanges(); } } }
public void AddTag(Tag t) { using (var context = new QuestionAnswerContext(_conn)) { context.Tags.Add(t); context.SaveChanges(); } }
public void AddAnswer(Answer answer) { using (var context = new QuestionAnswerContext(_conn)) { answer.Date = DateTime.Now; context.Add(answer); context.SaveChanges(); } }
public void AddLikeAnswer(int answerId, int userId) { using (var context = new QuestionAnswerContext(_conn)) { context.UserAnswerLikes.Add(new UserAnswerLikes { AnswerId = answerId, UserId = userId }); context.SaveChanges(); } }
public void AddUser(User u) { using (var context = new QuestionAnswerContext(_conn)) { //first check if the email already exists for a user var user = GetUserByEmail(u.Email); if (user is null) { u.PasswordHash = BCrypt.Net.BCrypt.HashPassword(u.PasswordHash); BCrypt.Net.BCrypt.HashPassword(u.PasswordHash); context.Users.Add(u); context.SaveChanges(); } } }
public void AddLikeQuestion(int questionId, int userId) { using (var context = new QuestionAnswerContext(_conn)) { var question = GetQuestionById(questionId); context.UserQuestionLikes.Add(new UserQuestionLikes { QuestionId = questionId, UserId = userId }); context.SaveChanges(); //return (question.UserQuestionLikes.Count()); } }