Exemplo n.º 1
0
        public bool CreateComment(PostMessage post, CommentCreate model)
        {
            var entity =
                new Comment()
            {
                Text   = model.Text,
                Author = _userId,
                Post   = new Post()
                {
                    Author  = post.Author,
                    Id      = post.Id,
                    Comment = post.Comment,
                    Text    = post.Text,
                    Title   = post.Title
                },
                PostId = post.Id
            };

            using (var ctx = new ApplicationDbContext())
            {
                var postEntity =
                    ctx
                    .Posts
                    .Single(e => e.Author == _userId && e.Id == entity.PostId);

                postEntity.Comment.Add(entity);
                ctx.Comments.Add(entity);

                return(ctx.SaveChanges() == 2);
            }
        }
Exemplo n.º 2
0
        public bool CreateReply(PostMessage post, CommentMessage comment, ReplyCreate model)
        {
            var entity =
                new Reply()
            {
                Author  = _userId,
                Comment = new Comment()
                {
                    Id         = comment.Id,
                    Author     = comment.Author,
                    Post       = comment.Post,
                    PostId     = comment.PostId,
                    ReplyChain = comment.ReplyChain,
                    Text       = comment.Text
                },
                ParentCommentId = comment.Id,
                Post            = new Post()
                {
                    Author  = post.Author,
                    Comment = post.Comment,
                    Id      = post.Id,
                    Text    = post.Text,
                    Title   = post.Title
                },
                PostId = post.Id,
                Text   = model.Text
            };

            using (var ctx = new ApplicationDbContext())
            {
                comment.ReplyChain.Add(entity);
                ctx.Comments.Add(entity);

                return(ctx.SaveChanges() == 2);
            }
        }