Exemple #1
0
        /// <summary>
        /// 创建评论
        /// </summary>
        /// <param name="comment">待创建评论</param>
        /// <returns>创建成功返回true,否则返回false</returns>
        public bool Create(Comment comment)
        {
            //触发事件
            EventBus <Comment> .Instance().OnBefore(comment, new CommonEventArgs(EventOperationType.Instance().Create()));

            AuditService auditService = new AuditService();

            auditService.ChangeAuditStatusForCreate(comment.UserId, comment);


            //评论创建
            long commentId = Convert.ToInt64(commentRepository.Insert(comment));


            //更新父级ChildCount
            if (commentId > 0)
            {
                ICommentBodyProcessor commentBodyProcessor = DIContainer.Resolve <ICommentBodyProcessor>();
                comment.Body = commentBodyProcessor.Process(comment.Body, TenantTypeIds.Instance().Comment(), commentId, comment.UserId);
                commentRepository.Update(comment);

                commentRepository.UpdateChildCount(comment.ParentId, false);
                CountService countService = new CountService(comment.TenantTypeId);
                countService.ChangeCount(CountTypes.Instance().CommentCount(), comment.CommentedObjectId, comment.OwnerId, 1, true);
                //触发事件
                EventBus <Comment> .Instance().OnAfter(comment, new CommonEventArgs(EventOperationType.Instance().Create()));

                EventBus <Comment, AuditEventArgs> .Instance().OnAfter(comment, new AuditEventArgs(null, comment.AuditStatus));
            }

            return(commentId > 0);
        }
Exemple #2
0
        /// <summary>
        /// 获取解析后的内容
        /// </summary>
        /// <param name="id">评论Id</param>
        /// <returns></returns>
        public string GetResolvedBody(long id)
        {
            Comment comment = Get(id);

            if (comment == null)
            {
                return(string.Empty);
            }

            ICacheService cacheService = DIContainer.Resolve <ICacheService>();

            string cacheKey    = string.Format("CommentResolvedBody{0}::{1}", RealTimeCacheHelper.GetEntityVersion(id), id);
            string resolveBody = cacheService.Get <string>(cacheKey);

            if (string.IsNullOrEmpty(resolveBody))
            {
                resolveBody = comment.Body;
                ICommentBodyProcessor commentBodyProcessor = DIContainer.Resolve <ICommentBodyProcessor>();
                resolveBody = commentBodyProcessor.Process(comment.Body, TenantTypeIds.Instance().Comment(), comment.Id, comment.UserId);
                cacheService.Set(cacheKey, resolveBody, CachingExpirationType.SingleObject);
            }

            return(resolveBody);
        }