예제 #1
0
 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();
     }
 }
예제 #2
0
 public void AddAnswer(Answer answer)
 {
     using (var context = new QuestionsTagsContext(_conn))
     {
         context.Answers.Add(answer);
         context.SaveChanges();
     }
 }
예제 #3
0
 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);
     }
 }
예제 #4
0
 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();
     }
 }
예제 #5
0
        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();
            }
        }