/// <summary> /// 创建评论 /// </summary> /// <param name="userId"></param> /// <param name="userName"></param> /// <param name="articleId"></param> /// <param name="content"></param> /// <param name="replyComment">回复的评论</param> public Comment(long?userId, string userName, long articleId, string content, Comment replyComment = null) { if (string.IsNullOrEmpty(content)) { throw new ArgumentNullException(nameof(content)); } SetId(); BloggerInfo = new BloggerInfo(userId, userName); _articleId = articleId; Content = content; Status = EntityStatusEnum.Available; ReplyComment(replyComment); _createTime = DateTime.Now; AddDomainEvent(new CreateCommentEvent(BloggerInfo.UserId, _articleId)); }
/// <summary> /// 回复评论 /// </summary> /// <param name="comment"></param> private void ReplyComment(Comment comment) { if (comment == null) { return; } IsSubComment = 1; if (comment.IsSubComment == 0) { //回复的是主评论 ReplyMainCommentId = comment.Id; } else { //回复的是子评论 ReplyMainCommentId = comment.ReplyMainCommentId; ReplySubCommentId = comment.Id; ReplySubBloggerInfo = new BloggerInfo(comment.BloggerInfo.UserId, comment.BloggerInfo.UserName); } }