예제 #1
0
 public int DeletePost(int id)
 {
     using (ModelPostEntities ctx = new ModelPostEntities())
     {
         return(ctx.Database.ExecuteSqlCommand("Delete from Posts where postid = @p0", id));
     }
 }
예제 #2
0
 public List <Post> GetAllPosts()
 {
     using (ModelPostEntities ctx = new ModelPostEntities())
     {
         return(ctx.Posts.Include("Comments").ToList <Post>());
     }
 }
예제 #3
0
 public Comment GetCommentById(int id)
 {
     using (ModelPostEntities ctx = new ModelPostEntities())
     {
         var items = from c in ctx.Comments where (c.CommentId == id) select c;
         return(items.Include(p => p.PostPostId1).SingleOrDefault());
     }
 }
예제 #4
0
        public PostComment.Post GetPostById(int Id)
        {
            using (ModelPostEntities ctx = new ModelPostEntities())
            {
                var items = from p in ctx.Posts where (p.PostId == Id) select p;
                if (items != null)
                {
                    return(items.Include(c => c.Comments).SingleOrDefault());
                }

                return(null);
            }
        }
예제 #5
0
        public bool AddPost()
        {
            using (var context = new ModelPostEntities())
            {
                var bResult = false;
                if (this.PostId == 0)
                {
                    var it = context.Entry <Post>(this).State = EntityState.Added;
                    context.SaveChanges();
                    bResult = true;
                }

                return(bResult);
            }
        }
예제 #6
0
 public PostComment.Post UpdatePost(PostComment.Post newPost)
 {
     using (ModelPostEntities ctx = new ModelPostEntities())
     {
         PostComment.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);
     }
 }
예제 #7
0
        public Comment UpdateComment(Comment newComment)
        {
            using (ModelPostEntities ctx = new ModelPostEntities())
            {
                Comment oldComment = ctx.Comments.Find(newComment.CommentId);
                if (newComment.Text != null)
                {
                    oldComment.Text = newComment.Text;
                }

                if ((oldComment.PostPostId1 != newComment.PostPostId1) && newComment.PostPostId1 != 0)
                {
                    oldComment.PostPostId1 = newComment.PostPostId1;
                }

                ctx.SaveChanges();
                return(oldComment);
            }
        }
예제 #8
0
        public bool AddComment()
        {
            using (ModelPostEntities ctx = new ModelPostEntities())
            {
                bool bResult = false;
                if (this == null || this.PostPostId1 == 0)
                {
                    return(bResult);
                }

                if (this.CommentId == 0)
                {
                    ctx.Entry <Comment>(this).State = EntityState.Added;
                    Post p = ctx.Posts.Find(this.PostPostId1);
                    ctx.Entry <Post>(p).State = EntityState.Unchanged;
                    ctx.SaveChanges();
                    bResult = true;
                }

                return(bResult);
            }
        }