Пример #1
0
 // Comment table
 public static bool AddComment(Comment comment)
 {
     using (ModelDesignContainer ctx = new ModelDesignContainer())
     {
         bool bResult = false;
         if (comment == null || comment.PostPostId == 0)
         {
             return(bResult);
         }
         if (comment.CommentId == 0)
         {
             ctx.Entry <Comment>(comment).State = EntityState.Added;
             Post p = ctx.Posts.Find(comment.PostPostId);
             ctx.Entry <Post>(p).State = EntityState.Unchanged;
             ctx.SaveChanges();
             bResult = true;
         }
         return(bResult);
     }
 }
Пример #2
0
 public static bool AddPost(Post post)
 {
     using (ModelDesignContainer ctx = new ModelDesignContainer())
     {
         bool bResult = false;
         if (post.PostId == 0)
         {
             var it = ctx.Entry <Post>(post).State = EntityState.Added;
             ctx.SaveChanges();
             bResult = true;
         }
         return(bResult);
     }
 }