public async Task <CreateCommentResponse> CreatePostComment(Guid postId, [FromBody] CreateCommentRequest model)
        {
            var comment = new Models.PostComment
            {
                Comment   = model.Comment,
                OwnerId   = CurrentUserId,
                OwnerName = User.Identity.Name,
                PostId    = postId
            };

            await _postCommentRepo.AddAsync(comment);

            var response = new CreateCommentResponse
            {
                Id          = comment.Id,
                Comment     = comment.Comment,
                PostId      = comment.PostId,
                OwnerName   = comment.OwnerName,
                CreatedDate = comment.Created
            };

            await _postMessageHubContext.Clients.All.InvokeAsync("AddCommentSuccess", response);

            return(response);
        }
Esempio n. 2
0
        public void Add(int PostId, string title, string content, string commentauthor)
        {
            var currentPostId = _context.Posts.First(s => s.Id == PostId).Id;
            var Comment       = new Models.PostComment
            {
                PostId        = currentPostId,
                Title         = title,
                Content       = content,
                CommentAuthor = commentauthor
            };

            _context.PostComments.Add(Comment);
            _context.SaveChanges();
        }
        public ActionResult Create(PostCommentViewModel theComment)
        {
            var         user    = this.PersistenceContext.Users.FirstOrDefault(u => u.UserName == theComment.CommentAuthor);
            var         post    = this.PersistenceContext.Posts.FirstOrDefault(p => p.Id == theComment.CommentedPostID);
            PostComment comment = new Models.PostComment
            {
                Content       = theComment.Content,
                CommentedPost = post,
                CommentAuthor = user,
            };

            this.PersistenceContext.PostsComments.Add(comment);
            this.PersistenceContext.SaveChanges();

            return(RedirectToAction("Index", "Post"));
        }