Blog.Services.Implementation.CommentsService.Add C# (CSharp) Method

Add() public method

public Add ( Comment comment ) : Comment
comment Blog.Common.Contracts.Comment
return Blog.Common.Contracts.Comment
        public Comment Add(Comment comment)
        {
            var postId = comment.PostId;
            if (comment.ParentCommentId != null)
            {
                comment.PostId = null;
            }

            var result = _commentsLogic.Add(comment);
            if (result != null && result.Error != null) throw new Exception(result.Error.Message);

            var commentAdded = new CommentAdded
            {
                CommentId = comment.ParentCommentId,
                PostId = postId,
                Comment = result,
                ClientFunction = Constants.SocketClientFunctions.CommentAdded.ToString()
            };

            _redisService.Publish(commentAdded);
            return result;
        }