コード例 #1
0
ファイル: Comment.cs プロジェクト: Tifir98/.NetLab6
 public bool AddComment()
 {
     using (ModelPostCommentContainer ctx = new ModelPostCommentContainer())
     {
         bool bResult = false;
         if (this == null || this.PostPostId == 0)
         {
             return(bResult);
         }
         if (this.CommentId == 0)
         {
             ctx.Entry <Comment>(this).State = EntityState.Added;
             Post p = ctx.Posts.Find(this.PostPostId);
             ctx.Entry <Post>(p).State = EntityState.Unchanged;
             ctx.SaveChanges();
             bResult = true;
         }
         return(bResult);
     }
 }
コード例 #2
0
ファイル: Post.cs プロジェクト: Tifir98/.NetLab6
 public bool AddPost()
 {
     using (ModelPostCommentContainer ctx = new ModelPostCommentContainer())
     {
         bool bResult = false;
         if (this.PostId == 0)
         {
             var it = ctx.Entry <Post>(this).State = EntityState.Added;
             ctx.SaveChanges(); bResult = true;
         }
         return(bResult);
     }
 }