Esempio n. 1
0
 public int DeletePost(int id)
 {
     using (ModelPostCommentContainer context = new ModelPostCommentContainer())
     {
         Post post = context.Posts.Find(id);
         context.Posts.Remove(post);
         context.SaveChanges();
         return(id);
     }
 }
Esempio n. 2
0
 public bool AddPost()
 {
     using (ModelPostCommentContainer context = new ModelPostCommentContainer())
     {
         if (this.PostId == 0)
         {
             var it = context.Entry <Post>(this).State = EntityState.Added;
             context.SaveChanges();
             return(true);
         }
         return(false);
     }
 }
Esempio n. 3
0
 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);
     }
 }
Esempio n. 4
0
 public Post UpdatePost(Post newPost)
 {
     using (ModelPostCommentContainer ctx = new ModelPostCommentContainer())
     {
         Post oldPost = ctx.Posts.Find(newPost.PostId);
         if (oldPost == null)
         {
             return(null);
         }
         oldPost.Description = newPost.Description;
         oldPost.Domain      = newPost.Domain;
         oldPost.Date        = newPost.Date;
         ctx.SaveChanges();
         return(oldPost);
     }
 }
Esempio n. 5
0
 public bool AddComment()
 {
     using (ModelPostCommentContainer ctx = new ModelPostCommentContainer())
     {
         bool bResult = false;
         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);
     }
 }
Esempio n. 6
0
 public Comment UpdateComment(Comment newComment)
 {
     using (ModelPostCommentContainer ctx = new ModelPostCommentContainer())
     {
         Comment oldComment = ctx.Comments.Find(newComment.CommentId);
         if (newComment.Text != null)
         {
             oldComment.Text = newComment.Text;
         }
         if ((oldComment.PostPostId != newComment.PostPostId) && (newComment.PostPostId != 0))
         {
             oldComment.PostPostId = newComment.PostPostId;
         }
         ctx.SaveChanges();
         return(oldComment);
     }
 }
Esempio n. 7
0
 public bool AddComment()
 {
     using (ModelPostCommentContainer context = new ModelPostCommentContainer())
     {
         if (this == null || this.PostPostId == 0)
         {
             return(false);
         }
         if (this.CommentId == 0)
         {
             context.Entry <Comment>(this).State = EntityState.Added;
             Post p = context.Posts.Find(this.PostPostId);
             context.Entry <Post>(p).State = EntityState.Unchanged;
             context.SaveChanges();
             return(true);
         }
         return(false);
     }
 }