예제 #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);
        }
예제 #2
0
        /// <summary>
        /// 删除评论
        /// </summary>
        /// <param name="id">评论Id</param>
        /// <returns>删除成功返回true,否则返回false</returns>
        public bool Delete(long id)
        {
            Comment comment  = commentRepository.Get(id);
            long    parentID = 0;
            int     count    = 0;

            if (comment != null)
            {
                //触发事件
                EventBus <Comment> .Instance().OnBefore(comment, new CommonEventArgs(EventOperationType.Instance().Delete()));

                parentID = comment.ParentId;

                count = commentRepository.Delete(id);

                if (count > 0)
                {
                    commentRepository.UpdateChildCount(parentID, true);
                    CountService countService = new CountService(comment.TenantTypeId);
                    countService.ChangeCount(CountTypes.Instance().CommentCount(), comment.CommentedObjectId, comment.OwnerId, -1 - comment.ChildCount, true);

                    //触发事件
                    EventBus <Comment> .Instance().OnAfter(comment, new CommonEventArgs(EventOperationType.Instance().Delete()));
                }
            }
            return(count > 0);
        }
예제 #3
0
        //关于缓存期限:
        //1、PointItem实体、列表 使用CachingExpirationType.RelativelyStable
        //2、PointCategory实体、列表 使用CachingExpirationType.RelativelyStable
        //3、PointRecord实体、列表 使用正常的缓存策略
        //4、积分记录的所有积分类型都是0,则不创建

        #region 积分变更及记录

        /// <summary>
        /// 依据规则增减积分
        /// </summary>
        /// <param name="userId">增减积分的UserId</param>
        /// <param name="pointItemKey">积分项目标识</param>
        /// <param name="description">积分记录描述</param>
        public void GenerateByRole(long userId, string pointItemKey, string description)
        {
            //1、依据pointItemKey查找积分项目,如果未找到则中断执行;
            PointItem pointItem = GetPointItem(pointItemKey);

            if (pointItem == null)
            {
                return;
            }
            if (pointItem.ExperiencePoints == 0 && pointItem.ReputationPoints == 0 && pointItem.TradePoints == 0)
            {
                return;
            }
            //2、检查用户当日各类积分是否达到限额,如果达到限额则不加积分,如果未达到则更新当日积分限额
            Dictionary <string, int> dictionary = pointStatisticRepository.UpdateStatistic(userId, GetPointCategory2PointsDictionary(pointItem));

            //如果用户当日各类积分都超出限额,则不产生积分
            if (dictionary.Count(n => n.Value != 0) == 0)
            {
                return;
            }

            //3、按照pointItemKey对应的积分项目,生成积分记录,并对用户积分额进行增减;

            int experiencePoints = dictionary[PointCategoryKeys.Instance().ExperiencePoints()];
            int reputationPoints = dictionary[PointCategoryKeys.Instance().ReputationPoints()];
            int tradePoints      = dictionary[PointCategoryKeys.Instance().TradePoints()];
            int tradePoints2     = 0;
            int tradePoints3     = 0;
            int tradePoints4     = 0;

            if (dictionary.ContainsKey("TradePoints2"))
            {
                tradePoints2 = dictionary["TradePoints2"];
            }
            if (dictionary.ContainsKey("TradePoints3"))
            {
                tradePoints3 = dictionary["TradePoints3"];
            }
            if (dictionary.ContainsKey("TradePoints4"))
            {
                tradePoints4 = dictionary["TradePoints4"];
            }

            PointRecord pointRecord = new PointRecord(userId, pointItem.ItemName, description, experiencePoints, reputationPoints, tradePoints);

            pointRecord.TradePoints2 = tradePoints2;
            pointRecord.TradePoints3 = tradePoints3;
            pointRecord.TradePoints4 = tradePoints4;
            pointRecordRepository.Insert(pointRecord);
            IUserService userService = DIContainer.Resolve <IUserService>();

            userService.ChangePoints(userId, experiencePoints, reputationPoints, tradePoints, tradePoints2, tradePoints3, tradePoints4);

            CountService countService = new CountService(TenantTypeIds.Instance().User());

            countService.ChangeCount(CountTypes.Instance().ReputationPointsCounts(), userId, userId, pointRecord.ReputationPoints);
        }
예제 #4
0
        /// <summary>
        /// 解析内容用于创建话题
        /// </summary>
        /// <param name="body">待解析的内容</param>
        /// <param name="ownerId">标签拥有者Id</param>
        /// <param name="associateId">关联项Id</param>
        /// <param name="tenantTypeId">租户类型Id</param>
        public void ResolveBodyForEdit(string body, long ownerId, long associateId, string tenantTypeId)
        {
            if (!body.Contains("#") || string.IsNullOrEmpty(body))
            {
                return;
            }

            Regex rg = new Regex(@"(?<=(?<!\&)(\#)(?!\d\;))[^\#@]*(?=(?<!\&)(\#)(?![0-9]+\;))", RegexOptions.Multiline | RegexOptions.Singleline);
            Match m  = rg.Match(body);

            if (!m.Success)
            {
                return;
            }

            IList <string> tagNames = new List <string>();
            int            i = 0, index = -1;

            while (m != null)
            {
                if (i % 2 == 1)
                {
                    m = m.NextMatch();
                    i++;
                    continue;
                }

                if (index == m.Index)
                {
                    break;
                }

                index = m.Index;

                if (!string.IsNullOrEmpty(m.Value) && !tagNames.Contains(m.Value))
                {
                    tagNames.Add(m.Value);
                }
                else
                {
                    continue;
                }

                m = m.NextMatch();
                i++;
            }

            if (tagNames.Count > 0)
            {
                CountService countService = new CountService(TenantTypeIds.Instance().Tag());
                AddTagsToItem(tagNames.ToArray(), ownerId, associateId);

                Dictionary <string, long> tagNamesWithIds = GetTagNamesWithIdsOfItem(associateId);
                if (tagNamesWithIds != null)
                {
                    foreach (KeyValuePair <string, long> pair in tagNamesWithIds)
                    {
                        countService.ChangeCount(CountTypes.Instance().ItemCounts(), pair.Value, ownerId, 1);
                    }
                }
            }
        }