public void AddQuestion(Question q, IEnumerable <string> tags) { using (var context = new QuestionsTagsContext(_conn)) { context.Questions.Add(q); foreach (string tag in tags) { Tag t = GetTag(tag); int tagId; if (t == null) { tagId = AddTag(tag); } else { tagId = t.Id; } context.QuestionsTags.Add(new QuestionsTags { QuestionId = q.Id, TagId = tagId }); } context.SaveChanges(); } }
public void AddAnswer(Answer answer) { using (var context = new QuestionsTagsContext(_conn)) { context.Answers.Add(answer); context.SaveChanges(); } }
private int AddTag(string name) { using (var context = new QuestionsTagsContext(_conn)) { var tag = new Tag { Name = name }; context.Tags.Add(tag); context.SaveChanges(); return(tag.Id); } }
public void AddUser(User u) { using (var context = new QuestionsTagsContext(_conn)) { var user = new User { Name = u.Name, Email = u.Email, Password = HashPassword(u.Password) }; context.Users.Add(user); context.SaveChanges(); } }
public void AddLike(int questionId, User u) { using (var context = new QuestionsTagsContext(_conn)) { var user = GetUser(u); Likes like = new Likes { UserId = user.Id, //User = user, QuestionId = questionId, //Question = context.Questions.FirstOrDefault(q => q.Id == questionId) }; context.Likes.Add(like); context.SaveChanges(); } }