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

Add() public method

public Add ( CommentLike commentLike ) : void
commentLike Blog.Common.Contracts.CommentLike
return void
        public void Add(CommentLike commentLike)
        {
            var result = _commentLikesLogic.Add(commentLike);
            if (result != null && result.Error != null) throw new Exception(result.Error.Message);

            var parentComment = _commentsLogic.Get(commentLike.CommentId);
            if (parentComment == null) throw new Exception(string.Format(
                "Failed to like comment {0} due to error in fetching comment", commentLike.CommentId));

            var commentLikes = _commentLikesLogic.Get(commentLike.CommentId);
            if (commentLikes == null) throw new Exception(string.Format(
                "Failed to like comment {0} due to error in fetching likes in comment", commentLike.CommentId));

            var commentLikesUpdate = new CommentLikesUpdate
            {
                CommentId = commentLike.CommentId,
                PostId = parentComment.PostId,
                CommentLikes = commentLikes,
                ClientFunction = Constants.SocketClientFunctions.CommentLikesUpdate.ToString()
            };

            _redisService.Publish(commentLikesUpdate);
        }
    }