Esempio n. 1
0
        public static bool AddComment(Comment comment)
        {
            using (var ctx = new ModelPostEntities())
            {
                var bResult = false;
                if (comment == null || comment.PostPostId1 == 0)
                {
                    return(bResult);
                }
                if (comment.CommentId == 0)
                {
                    ctx.Entry(comment).State = EntityState.Added;
                    var p = ctx.Posts.Find(comment.PostPostId);
                    ctx.Entry(p).State = EntityState.Unchanged;
                    ctx.SaveChanges();
                    bResult = true;
                }

                return(bResult);
            }
        }
Esempio n. 2
0
        public static bool AddPost(Post post)
        {
            using (var ctx = new ModelPostEntities())
            {
                var bResult = false;
                if (post.PostId == 0)
                {
                    var it = ctx.Entry(post).State = EntityState.Added;
                    ctx.SaveChanges();
                    bResult = true;
                }

                return(bResult);
            }
        }