Ejemplo n.º 1
0
        /// <summary>
        /// 采纳满意回答
        /// </summary>
        /// <remarks>
        /// 1.如果问题有悬赏则悬赏分值转移到回答者的帐户(如有交易税,需要扣除),通过EventModule实现
        /// 2.除了悬赏分的交易,回答被采纳,回答者还会获得新产生的积分,通过EventModule实现
        /// 3.注意需要发送通知给问题的关注者,通过EventModule实现
        /// 4.需要触发的事件:SetBestAnswer的OnAfter
        /// </remarks>
        /// <param name="question">问题实体</param>
        /// <param name="answer">回答实体</param>
        public void SetBestAnswer(AskQuestion question, AskAnswer answer)
        {
            if (!answer.IsBest)
            {
                answer.IsBest = true;

                //调用Service中的Update方法,以触发相应的事件,但是不更新审核状态
                this.UpdateAnswer(answer, false);
                //todo:jiangshl,改为EventModule处理
                //处理威望
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());

                //用户获得威望值
                PointService pointService = new PointService();
                //提问者获取威望值
                PointItem questionPointItem = pointService.GetPointItem(PointItemKeys.Instance().Ask_AcceptedAnswer());
                ownerDataService.Change(question.UserId, OwnerDataKeys.Instance().UserAskReputation(), questionPointItem.ReputationPoints);
                //回答者获得威望
                PointItem AnswerPointItem = pointService.GetPointItem(PointItemKeys.Instance().Ask_AnswerWereAccepted());
                ownerDataService.Change(answer.UserId, OwnerDataKeys.Instance().UserAskReputation(), AnswerPointItem.ReputationPoints);

                //用户计数
                ownerDataService.Change(answer.UserId, OwnerDataKeys.Instance().AnswerAcceptCount(), 1);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 更换群主
        /// </summary>
        /// <param name="groupId">专题Id</param>
        /// <param name="newOwnerUserId">新群主UserId</param>
        public void ChangeTopicOwner(long groupId, long newOwnerUserId)
        {
            //更换群主后,原群主转换成专题成员,如果新群主是专题成员则从成员中移除
            TopicEntity group          = groupRepository.Get(groupId);
            long        oldOwnerUserId = group.UserId;

            group.UserId = newOwnerUserId;
            groupRepository.ChangeTopicOwner(groupId, newOwnerUserId);

            //原群主的专题数-1,加入专题数+1
            OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());

            ownerDataService.Change(oldOwnerUserId, OwnerDataKeys.Instance().CreatedTopicCount(), -1);
            ownerDataService.Change(oldOwnerUserId, OwnerDataKeys.Instance().JoinedTopicCount(), 1);

            //原群主转换成专题成员
            TopicMember TopicMember = TopicMember.New();

            TopicMember.TopicId = groupId;
            TopicMember.UserId  = oldOwnerUserId;
            TopicMemberRepository.Insert(TopicMember);

            //新群主的专题数+1,加入专题数-1
            ownerDataService.Change(newOwnerUserId, OwnerDataKeys.Instance().CreatedTopicCount(), 1);

            //如果新群主是专题成员则从成员中移除
            if (IsMember(groupId, newOwnerUserId))
            {
                DeleteTopicMember(groupId, newOwnerUserId);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 更换群主
        /// </summary>
        /// <param name="groupId">群组Id</param>
        /// <param name="newOwnerUserId">新群主UserId</param>
        public void ChangeGroupOwner(long groupId, long newOwnerUserId)
        {
            //更换群主后,原群主转换成群组成员,如果新群主是群组成员则从成员中移除
            GroupEntity group          = groupRepository.Get(groupId);
            long        oldOwnerUserId = group.UserId;

            group.UserId = newOwnerUserId;
            groupRepository.ChangeGroupOwner(groupId, newOwnerUserId);

            //原群主的群组数-1,加入群组数+1
            OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());

            ownerDataService.Change(oldOwnerUserId, OwnerDataKeys.Instance().CreatedGroupCount(), -1);
            ownerDataService.Change(oldOwnerUserId, OwnerDataKeys.Instance().JoinedGroupCount(), 1);

            //原群主转换成群组成员
            GroupMember groupMember = GroupMember.New();

            groupMember.GroupId = groupId;
            groupMember.UserId  = oldOwnerUserId;
            groupMemberRepository.Insert(groupMember);

            //新群主的群组数+1,加入群组数-1
            ownerDataService.Change(newOwnerUserId, OwnerDataKeys.Instance().CreatedGroupCount(), 1);

            //如果新群主是群组成员则从成员中移除
            if (IsMember(groupId, newOwnerUserId))
            {
                DeleteGroupMember(groupId, newOwnerUserId);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 删除微博
        /// </summary>
        /// <param name="microblogId">微博Id</param>
        public void Delete(long microblogId)
        {
            MicroblogEntity entity = Get(microblogId);

            if (entity == null)
            {
                return;
            }

            var sender = new CommentService().GetCommentedObjectComments(microblogId);



            EventBus <MicroblogEntity> .Instance().OnBefore(entity, new CommonEventArgs(EventOperationType.Instance().Delete()));

            int affect = microblogRepository.Delete(entity);

            if (affect > 0)
            {
                //删除微博时评论的积分处理
                if (sender != null)
                {
                    EventBus <Comment> .Instance().OnBatchAfter(sender, new CommonEventArgs(EventOperationType.Instance().Delete()));
                }
                //更新用户数据
                OwnerDataService ownerDataService = new OwnerDataService(entity.TenantTypeId);
                ownerDataService.Change(entity.OwnerId, OwnerDataKeys.Instance().ThreadCount(), -1);

                EventBus <MicroblogEntity> .Instance().OnAfter(entity, new CommonEventArgs(EventOperationType.Instance().Delete()));

                EventBus <MicroblogEntity, AuditEventArgs> .Instance().OnAfter(entity, new AuditEventArgs(entity.AuditStatus, null));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 发布问题
        /// </summary>
        /// <remarks>
        /// 1.用户提问时,悬赏的积分会被冻结,需要先扣除相应的用户积分;同时发布问题会产生新积分
        /// 2.注意在EventModule中处理动态、积分、通知、自动关注(提问者自动关注该问题);
        /// 3.使用AuditService.ChangeAuditStatusForCreate设置审核状态;
        /// 4.注意调用AttachmentService转换临时附件;
        /// 5.需要触发的事件:1)Create的OnBefore、OnAfter;2)审核状态变更;
        /// </remarks>
        /// <param name="question">问题实体</param>
        /// <returns>是否创建成功</returns>
        public bool CreateQuestion(AskQuestion question)
        {
            EventBus <AskQuestion> .Instance().OnBefore(question, new CommonEventArgs(EventOperationType.Instance().Create()));

            //设置审核状态
            new AuditService().ChangeAuditStatusForCreate(question.UserId, question);

            askQuestionRepository.Insert(question);
            if (question.QuestionId > 0)
            {
                //将临时附件转换为正式附件
                AttachmentService attachmentService = new AttachmentService(TenantTypeIds.Instance().AskQuestion());
                attachmentService.ToggleTemporaryAttachments(question.UserId, TenantTypeIds.Instance().AskQuestion(), question.QuestionId);

                //用户计数
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(question.UserId, OwnerDataKeys.Instance().QuestionCount(), 1);

                AtUserService atUserService = new AtUserService(TenantTypeIds.Instance().AskQuestion());
                atUserService.ResolveBodyForEdit(question.Body, question.UserId, question.QuestionId);


                EventBus <AskQuestion> .Instance().OnAfter(question, new CommonEventArgs(EventOperationType.Instance().Create()));

                EventBus <AskQuestion, AuditEventArgs> .Instance().OnAfter(question, new AuditEventArgs(null, question.AuditStatus));
            }

            return(question.QuestionId > 0);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 创建群组
        /// </summary>
        /// <param name="userId">当前操作人</param>
        /// <param name="group"><see cref="GroupEntity"/></param>
        /// <param name="logoFile">群组标识图</param>
        /// <returns>创建成功返回true,失败返回false</returns>
        public bool Create(long userId, GroupEntity group)
        {
            //设计要点
            //1、使用AuditService设置审核状态;
            //2、需要触发的事件参见《设计说明书-日志》
            //3、单独调用标签服务设置标签
            //4、使用 IdGenerator.Next() 生成GroupId
            EventBus <GroupEntity> .Instance().OnBefore(group, new CommonEventArgs(EventOperationType.Instance().Create()));

            //设置审核状态
            auditService.ChangeAuditStatusForCreate(userId, group);
            long id = 0;

            long.TryParse(groupRepository.Insert(group).ToString(), out id);

            if (id > 0)
            {
                EventBus <GroupEntity> .Instance().OnAfter(group, new CommonEventArgs(EventOperationType.Instance().Create()));

                EventBus <GroupEntity, AuditEventArgs> .Instance().OnAfter(group, new AuditEventArgs(null, group.AuditStatus));

                //用户的创建群组数+1
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(group.UserId, OwnerDataKeys.Instance().CreatedGroupCount(), 1);
            }
            return(id > 0);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 是否批准申请
        /// </summary>
        /// <remarks>
        /// 1.需要触发的事件:1)Update的OnBefore、OnAfter;
        /// 2.如果申请通过,则不能被取消。
        /// 3.申请通过后触发动态,通知。
        /// 4.申请被否决后,积分返还。
        /// </remarks>
        /// <param name="record">记录对象</param>
        /// <param name="isApprove">是否批准</param>
        public void IsApprove(PointGiftExchangeRecord record, bool isApprove)
        {
            if (isApprove)
            {
                PointGift gift = this.GetGift(record.GiftId);
                record.LastModified = DateTime.UtcNow;
                record.Status       = ApproveStatus.Approved;
                gift.ExchangedCount = gift.ExchangedCount + record.Number;
                giftRepository.Update(gift);
                pointService.TradeToSystem(record.PayerUserId, record.Price, "兑换商品", false);
                EventBus <PointGiftExchangeRecord> .Instance().OnAfter(record, new CommonEventArgs(EventOperationType.Instance().Approved()));
            }
            else
            {
                record.Status = ApproveStatus.Rejected;
                userService.UnfreezeTradePoints(record.PayerUserId, record.Price);
                EventBus <PointGiftExchangeRecord> .Instance().OnAfter(record, new CommonEventArgs(EventOperationType.Instance().Disapproved()));
            }

            //处理统计数据
            OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());

            ownerDataService.Change(record.PayerUserId, OwnerDataKeys.Instance().PostCount(), -1);

            recordRepository.Update(record);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 删除用户时处理其兑换申请
        /// </summary>
        /// <remarks>
        /// 1.如果需要接管,直接执行Repository的方法更新数据库记录
        /// 2.如果不需要接管,删除申请记录
        /// </remarks>
        /// <param name="userId">用户ID</param>
        /// <param name="takeOverUserName">指定接管用户的用户名</param>
        /// <param name="isTakeOver">是否接管</param>
        public void DeleteUser(long userId, string takeOverUserName, bool isTakeOver)
        {
            if (isTakeOver)
            {
                IUserService userService  = DIContainer.Resolve <IUserService>();
                User         takeOverUser = userService.GetFullUser(takeOverUserName);
                recordRepository.TakeOver(userId, takeOverUser);
            }
            else
            {
                //删除用户下申请
                int pageCount = 1;
                int pageIndex = 1;
                do
                {
                    PagingDataSet <PointGiftExchangeRecord> records = this.GetRecordsOfUser(userId, Convert.ToDateTime("2000-01-01"), DateTime.Now, null, 100, pageIndex);
                    foreach (PointGiftExchangeRecord record in records)
                    {
                        recordRepository.Delete(record);

                        //处理统计数据
                        OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                        ownerDataService.Change(record.PayerUserId, OwnerDataKeys.Instance().PostCount(), -1);
                    }
                    pageCount = records.PageCount;
                    pageIndex++;
                } while (pageIndex <= pageCount);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 删除回答
        /// </summary>
        /// <remarks>
        /// 1.管理员删除被采纳的回答时,需要将问题状态变更为“待解决”
        /// 2.注意维护相关问题的回答数,调用UpdateAskQuestion,AnswerCount--
        /// 3.注意需要删除动态,通过EventModule处理;
        /// 4.注意需要扣除增加的积分,通过EventModule处理;
        /// 5.注意需要删除回答者对问题的关注,通过EventModule处理;
        /// 6.需要触发的事件:1)Delete的OnBefore、OnAfter;2)审核状态变更
        /// </remarks>
        /// <param name="answer">回答实体</param>
        public void DeleteAnswer(AskAnswer answer)
        {
            EventBus <AskAnswer> .Instance().OnBefore(answer, new CommonEventArgs(EventOperationType.Instance().Delete()));

            askAnswerRepository.Delete(answer);

            //更新相关问题的内容
            AskQuestion question = askQuestionRepository.Get(answer.QuestionId);

            question.AnswerCount--;
            if (answer.IsBest)
            {
                question.Status = QuestionStatus.Unresolved;
            }
            //调用Service中的Update方法,以触发相应的事件,但是不更新审核状态
            this.UpdateQuestion(question, false);

            //用户计数
            OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());

            ownerDataService.Change(answer.UserId, OwnerDataKeys.Instance().AnswerCount(), -1);

            EventBus <AskAnswer> .Instance().OnAfter(answer, new CommonEventArgs(EventOperationType.Instance().Delete()));

            EventBus <AskAnswer, AuditEventArgs> .Instance().OnAfter(answer, new AuditEventArgs(answer.AuditStatus, null));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 增加专题成员
        /// </summary>
        /// <param name="TopicMember"></param>
        public void CreateTopicMember(TopicMember TopicMember)
        {
            //设计要点:
            //1、同一个专题不允许用户重复加入
            //2、群主不允许成为专题成员
            if (IsMember(TopicMember.TopicId, TopicMember.UserId))
            {
                return;
            }
            if (IsOwner(TopicMember.TopicId, TopicMember.UserId))
            {
                return;
            }
            long id = 0;

            long.TryParse(TopicMemberRepository.Insert(TopicMember).ToString(), out id);

            if (id > 0)
            {
                EventBus <TopicMember> .Instance().OnAfter(TopicMember, new CommonEventArgs(EventOperationType.Instance().Create()));

                //用户的参与专题数+1
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(TopicMember.UserId, OwnerDataKeys.Instance().JoinedTopicCount(), 1);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 增加群组成员
        /// </summary>
        /// <param name="groupMember"></param>
        public void CreateGroupMember(GroupMember groupMember)
        {
            //设计要点:
            //1、同一个群组不允许用户重复加入
            //2、群主不允许成为群组成员
            if (IsMember(groupMember.GroupId, groupMember.UserId))
            {
                return;
            }
            if (IsOwner(groupMember.GroupId, groupMember.UserId))
            {
                return;
            }
            long id = 0;

            long.TryParse(groupMemberRepository.Insert(groupMember).ToString(), out id);

            if (id > 0)
            {
                EventBus <GroupMember> .Instance().OnAfter(groupMember, new CommonEventArgs(EventOperationType.Instance().Create()));

                //用户的参与群组数+1
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(groupMember.UserId, OwnerDataKeys.Instance().JoinedGroupCount(), 1);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 删除日志
        /// </summary>
        /// <param name="blogThread">日志实体</param>
        public void Delete(BlogThread blogThread)
        {
            //删除日志可能会影响:
            //1、站点分类,在EventModule中处理
            //2、拥有者分类,在EventModule中处理
            //3、日志对应的动态(可在EventModule中处理,可参考贴吧)
            //4、其它数据的删除由各模块自动处理
            //需要触发的事件参见《设计说明书-日志》;

            if (blogThread == null)
            {
                return;
            }

            CategoryService categoryService = new CategoryService();

            var sender = new CommentService().GetCommentedObjectComments(blogThread.ThreadId);

            //删除用户分类关联
            categoryService.ClearCategoriesFromItem(blogThread.ThreadId, blogThread.OwnerId, TenantTypeIds.Instance().BlogThread());

            //删除站点分类关联(投稿到)
            categoryService.ClearCategoriesFromItem(blogThread.ThreadId, 0, TenantTypeIds.Instance().BlogThread());

            //删除标签关联
            TagService tagService = new TagService(TenantTypeIds.Instance().BlogThread());

            tagService.ClearTagsFromItem(blogThread.ThreadId, blogThread.OwnerId);

            //删除推荐记录
            RecommendService recommendService = new RecommendService();

            recommendService.Delete(blogThread.ThreadId, blogThread.TenantTypeId);

            //删除订阅记录todo:libsh
            //SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BlogThread());


            //用户内容计数-1
            if (!blogThread.IsDraft)
            {
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(blogThread.UserId, OwnerDataKeys.Instance().ThreadCount(), -1);
            }

            EventBus <BlogThread> .Instance().OnBefore(blogThread, new CommonEventArgs(EventOperationType.Instance().Delete()));

            blogThreadRepository.Delete(blogThread);

            EventBus <BlogThread> .Instance().OnAfter(blogThread, new CommonEventArgs(EventOperationType.Instance().Delete()));

            EventBus <BlogThread, AuditEventArgs> .Instance().OnAfter(blogThread, new AuditEventArgs(blogThread.AuditStatus, null));

            if (sender != null)
            {
                EventBus <Comment> .Instance().OnBatchAfter(sender, new CommonEventArgs(EventOperationType.Instance().Delete()));
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 创建回复贴
        /// </summary>
        /// <param name="post">回复贴</param>
        public bool Create(BarPost post)
        {
            BarSectionService barSectionService = new BarSectionService();
            BarSection        barSection        = barSectionService.Get(post.SectionId);

            if (barSection == null)
            {
                return(false);
            }

            EventBus <BarPost> .Instance().OnBefore(post, new CommonEventArgs(EventOperationType.Instance().Create()));

            //设置审核状态
            auditService.ChangeAuditStatusForCreate(post.UserId, post);
            long id = 0;

            long.TryParse(barPostRepository.Insert(post).ToString(), out id);

            if (id > 0)
            {
                new AttachmentService(TenantTypeIds.Instance().BarPost()).ToggleTemporaryAttachments(post.UserId, TenantTypeIds.Instance().BarPost(), id);

                //计数
                CountService countService = new CountService(TenantTypeIds.Instance().BarSection());
                countService.ChangeCount(CountTypes.Instance().ThreadAndPostCount(), barSection.SectionId, barSection.UserId, 1, true);
                if (post.TenantTypeId == TenantTypeIds.Instance().Group())
                {
                    //群组内容计数+1
                    OwnerDataService groupOwnerDataService = new OwnerDataService(TenantTypeIds.Instance().Group());
                    groupOwnerDataService.Change(post.SectionId, OwnerDataKeys.Instance().PostCount(), 1);
                }
                else if (post.TenantTypeId == TenantTypeIds.Instance().Bar())
                {
                    //用户内容计数+1
                    OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                    ownerDataService.Change(post.UserId, OwnerDataKeys.Instance().PostCount(), 1);
                }

                //更新帖子主题计数缓存
                RealTimeCacheHelper realTimeCacheHelper = EntityData.ForType(typeof(BarThread)).RealTimeCacheHelper;
                string        cacheKey     = realTimeCacheHelper.GetCacheKeyOfEntity(post.ThreadId);
                ICacheService cacheService = DIContainer.Resolve <ICacheService>();
                BarThread     barThread    = cacheService.Get <BarThread>(cacheKey);

                if (barThread != null && barThread.ThreadId > 0)
                {
                    barThread.PostCount++;
                    cacheService.Set(cacheKey, barThread, CachingExpirationType.SingleObject);
                }

                new AtUserService(TenantTypeIds.Instance().BarPost()).ResolveBodyForEdit(post.GetBody(), post.UserId, post.PostId);

                EventBus <BarPost> .Instance().OnAfter(post, new CommonEventArgs(EventOperationType.Instance().Create()));

                EventBus <BarPost, AuditEventArgs> .Instance().OnAfter(post, new AuditEventArgs(null, post.AuditStatus));
            }
            return(id > 0);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 删除照片
        /// </summary>
        /// <remarks>
        /// 1.更新所属相册计数PhotoCount-1
        /// 2.更新用户内容计数OwnerData-1
        /// 3.如果照片是封面,需要将相册的CoverId属性重置为0
        /// 4.需要调用TagService.ClearTagsFromItem删除标签关联
        /// 5.需要同步删除照片圈人
        /// 6.通过EventModule处理动态和积分的变化;
        /// 7.需要触发的事件:1)Delete的OnBefore、OnAfter;2)审核状态变更
        /// </remarks>
        /// <param name="photo">照片对象</param>
        public void DeletePhoto(Photo photo)
        {
            //删除与标签的关联
            TagService tagService = new TagService(TenantTypeIds.Instance().Photo());

            tagService.ClearTagsFromItem(photo.PhotoId, photo.UserId);

            //删除照片推荐
            RecommendService recommendService = new RecommendService();

            recommendService.Delete(photo.PhotoId, TenantTypeIds.Instance().Photo());

            //相册计数PhotoCount-1及封面
            Album album = photo.Album;

            album.PhotoCount--;
            if (photo.PhotoId == album.CoverId)
            {
                album.CoverId = 0;
            }
            albumRepository.Update(album);

            //删除圈人
            IEnumerable <PhotoLabel> photoLabels = this.GetLabelsOfPhoto(null, photo.PhotoId);

            foreach (PhotoLabel photolabel in photoLabels)
            {
                photoLabelRepository.Delete(photolabel);
            }

            //删除照片磁盘物理文件
            if (!string.IsNullOrEmpty(photo.RelativePath))
            {
                TenantAttachmentSettings tenantAttachmentSettings = TenantAttachmentSettings.GetRegisteredSettings(TenantTypeIds.Instance().Photo());
                IStoreProvider           storeProvider            = DIContainer.ResolveNamed <IStoreProvider>(tenantAttachmentSettings.StoreProviderName);
                string relativePath = storeProvider.GetRelativePath(photo.RelativePath, true);
                string fileName     = photo.RelativePath.Remove(0, relativePath.Length).Trim('\\').Trim('/');
                storeProvider.DeleteFiles(relativePath, fileName);
            }

            photoRepository.Delete(photo);

            EventBus <Photo> .Instance().OnBefore(photo, new CommonEventArgs(EventOperationType.Instance().Delete()));

            //用户内容计数OwnerData-1
            OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());

            ownerDataService.Change(photo.UserId, OwnerDataKeys.Instance().PhotoCount(), -1);

            //通过EventModule处理动态和积分的变化;
            EventBus <Photo> .Instance().OnAfter(photo, new CommonEventArgs(EventOperationType.Instance().Delete()));

            EventBus <Photo, AuditEventArgs> .Instance().OnAfter(photo, new AuditEventArgs(photo.AuditStatus, null));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 创建兑换记录
        /// </summary>
        /// <remarks>
        /// 1.冻结相应积分
        /// </remarks>
        /// <param name="record">记录对象</param>
        /// <returns></returns>
        public long CreateRecord(PointGiftExchangeRecord record)
        {
            if (record.Price > 0)
            {
                userService.FreezeTradePoints(record.PayerUserId, record.Price);

                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(record.PayerUserId, OwnerDataKeys.Instance().PostCount(), 1);
            }
            recordRepository.Insert(record);
            return(record.RecordId);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 删除群组下的成员
        /// </summary>
        /// <param name="groupId"></param>
        public void DeleteMembersByGroupId(long groupId)
        {
            IEnumerable <GroupMember> groupMembers = groupMemberRepository.GetAllMembersOfGroup(groupId);

            foreach (var groupMember in groupMembers)
            {
                int affectCount = groupMemberRepository.Delete(groupMember);
                if (affectCount > 0)
                {
                    EventBus <GroupMember> .Instance().OnAfter(groupMember, new CommonEventArgs(EventOperationType.Instance().Delete()));

                    //用户的参与群组数-1
                    OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                    ownerDataService.Change(groupMember.UserId, OwnerDataKeys.Instance().JoinedGroupCount(), -1);
                }
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 删除记录
        /// </summary>
        /// <remarks>
        /// 1.管理员无权删除兑换记录
        /// 2.记录已经批准则不能删除记录
        /// 3.冻结积分返还
        /// </remarks>
        /// <param name="record">记录对象</param>
        public bool CancelRecord(PointGiftExchangeRecord record)
        {
            if (record.Status == ApproveStatus.Pending)
            {
                userService.UnfreezeTradePoints(record.PayerUserId, record.Price);

                //处理统计数据
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(record.PayerUserId, OwnerDataKeys.Instance().PostCount(), -1);

                recordRepository.Delete(record);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 创建主题帖
        /// </summary>
        /// <param name="thread">主题帖</param>
        public bool Create(BarThread thread)
        {
            BarSectionService barSectionService = new BarSectionService();

            EventBus <BarThread> .Instance().OnBefore(thread, new CommonEventArgs(EventOperationType.Instance().Create()));

            //设置审核状态
            auditService.ChangeAuditStatusForCreate(thread.UserId, thread);
            long id = 0;

            long.TryParse(barThreadRepository.Insert(thread).ToString(), out id);

            if (id > 0)
            {
                new AttachmentService(TenantTypeIds.Instance().BarThread()).ToggleTemporaryAttachments(thread.UserId, TenantTypeIds.Instance().BarThread(), id);
                BarSection barSection = barSectionService.Get(thread.SectionId);
                if (barSection != null)
                {
                    //计数
                    CountService countService = new CountService(TenantTypeIds.Instance().BarSection());
                    countService.ChangeCount(CountTypes.Instance().ThreadCount(), barSection.SectionId, barSection.UserId, 1, true);
                    countService.ChangeCount(CountTypes.Instance().ThreadAndPostCount(), barSection.SectionId, barSection.UserId, 1, true);
                    if (thread.TenantTypeId == TenantTypeIds.Instance().Group())
                    {
                        //群组内容计数+1
                        OwnerDataService groupOwnerDataService = new OwnerDataService(TenantTypeIds.Instance().Group());
                        groupOwnerDataService.Change(thread.SectionId, OwnerDataKeys.Instance().ThreadCount(), 1);
                    }
                }
                if (thread.TenantTypeId == TenantTypeIds.Instance().Bar())
                {
                    //用户内容计数+1
                    OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                    ownerDataService.Change(thread.UserId, OwnerDataKeys.Instance().ThreadCount(), 1);
                }
                AtUserService atUserService = new AtUserService(TenantTypeIds.Instance().BarThread());
                atUserService.ResolveBodyForEdit(thread.GetBody(), thread.UserId, thread.ThreadId);

                EventBus <BarThread> .Instance().OnAfter(thread, new CommonEventArgs(EventOperationType.Instance().Create()));

                EventBus <BarThread, AuditEventArgs> .Instance().OnAfter(thread, new AuditEventArgs(null, thread.AuditStatus));
            }
            return(id > 0);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 创建微博
        /// </summary>
        /// <param name="microblog">待创建微博实体</param>
        /// <returns></returns>
        public long Create(MicroblogEntity microblog)
        {
            EventBus <MicroblogEntity> .Instance().OnBefore(microblog, new CommonEventArgs(EventOperationType.Instance().Create()));

            //设置审核状态
            auditService.ChangeAuditStatusForCreate(microblog.UserId, microblog);

            string videoAlias = string.Empty, audioAlias = string.Empty;

            microblog.Body       = parsedMediaService.ResolveBodyForEdit(microblog.Body, out videoAlias, out audioAlias);
            microblog.HasVideo   = !string.IsNullOrEmpty(videoAlias);
            microblog.HasMusic   = !string.IsNullOrEmpty(audioAlias);
            microblog.VideoAlias = videoAlias;
            microblog.AudioAlias = audioAlias;

            long id = 0;

            long.TryParse(microblogRepository.Insert(microblog).ToString(), out id);

            if (id > 0)
            {
                string tenantTypeId = TenantTypeIds.Instance().Microblog();

                OwnerDataService ownerDataService = new OwnerDataService(microblog.TenantTypeId);
                ownerDataService.Change(microblog.OwnerId, OwnerDataKeys.Instance().ThreadCount(), 1);


                //将临时附件转换为正式附件
                attachmentService.ToggleTemporaryAttachments(microblog.UserId, tenantTypeId, id);

                AtUserService atUserService = new AtUserService(tenantTypeId);
                atUserService.ResolveBodyForEdit(microblog.Body, microblog.UserId, microblog.MicroblogId);

                TagService tagService = new TagService(tenantTypeId);
                tagService.ResolveBodyForEdit(microblog.Body, microblog.OwnerId, microblog.MicroblogId, tenantTypeId);

                EventBus <MicroblogEntity> .Instance().OnAfter(microblog, new CommonEventArgs(EventOperationType.Instance().Create()));

                EventBus <MicroblogEntity, AuditEventArgs> .Instance().OnAfter(microblog, new AuditEventArgs(null, microblog.AuditStatus));
            }

            return(id);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 撰写词条
        /// </summary>
        /// <param name="wikiPage">词条实体</param>
        public bool Create(WikiPage wikiPage, string body)
        {
            EventBus <WikiPage> .Instance().OnBefore(wikiPage, new CommonEventArgs(EventOperationType.Instance().Create()));

            //设置审核状态,草稿的审核状态为待审核
            AuditService auditService = new AuditService();

            auditService.ChangeAuditStatusForCreate(wikiPage.UserId, wikiPage);

            long pageId = 0;

            long.TryParse(wikiPageRepository.Insert(wikiPage).ToString(), out pageId);

            if (pageId > 0)
            {
                WikiPageVersion wikiPageVersion = WikiPageVersion.New();
                wikiPageVersion.PageId       = pageId;
                wikiPageVersion.TenantTypeId = wikiPage.TenantTypeId;
                wikiPageVersion.OwnerId      = wikiPage.OwnerId;
                wikiPageVersion.VersionNum   = 1;
                wikiPageVersion.Title        = wikiPage.Title;
                wikiPageVersion.UserId       = wikiPage.UserId;
                wikiPageVersion.Author       = wikiPage.Author;
                wikiPageVersion.Summary      = StringUtility.Trim(Tunynet.Utilities.HtmlUtility.StripHtml(body, true, false).Replace("\r", "").Replace("\n", ""), 200);
                wikiPageVersion.Body         = body;
                wikiPageVersion.AuditStatus  = AuditStatus.Success;
                wikiPageVersionRepository.Insert(wikiPageVersion);
                //转换临时附件
                AttachmentService attachmentService = new AttachmentService(TenantTypeIds.Instance().WikiPage());
                attachmentService.ToggleTemporaryAttachments(wikiPage.OwnerId, TenantTypeIds.Instance().WikiPage(), wikiPageVersion.PageId);

                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(wikiPage.UserId, OwnerDataKeys.Instance().PageCount(), 1);

                EventBus <WikiPage> .Instance().OnAfter(wikiPage, new CommonEventArgs(EventOperationType.Instance().Create()));

                EventBus <WikiPage, AuditEventArgs> .Instance().OnAfter(wikiPage, new AuditEventArgs(null, wikiPage.AuditStatus));

                return(true);
            }

            return(false);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// 创建照片
        /// </summary>
        /// <remarks>
        /// 1.更新相册的PhotoCount+1
        /// 2.更新用户内容计数OwnerData+1
        /// 3.需要同步相册的TenantTypeId、OwnerId、UserId、Author、PrivacyStatus字段
        /// 4.注意在EventModule中处理动态、积分;
        /// 5.使用AuditService.ChangeAuditStatusForCreate设置审核状态;
        /// 6.需要触发的事件:1)Create的OnBefore、OnAfter;2)审核状态变更;
        /// </remarks>
        /// <param name="photo">照片对象</param>
        /// <param name="file">上传文件</param>
        /// <returns>返回是否成功创建</returns>
        public bool CreatePhoto(Photo photo, HttpPostedFileBase file)
        {
            EventBus <Photo> .Instance().OnBefore(photo, new CommonEventArgs(EventOperationType.Instance().Create()));

            Album album = photo.Album;

            //需要同步相册的TenantTypeId、OwnerId、UserId、Author、PrivacyStatus字段
            photo.TenantTypeId  = album.TenantTypeId;
            photo.OwnerId       = album.OwnerId;
            photo.UserId        = album.UserId;
            photo.Author        = photo.User != null ? photo.User.DisplayName : album.Author;
            photo.PrivacyStatus = album.PrivacyStatus;

            //设置审核状态
            new AuditService().ChangeAuditStatusForCreate(album.UserId, photo);

            //创建照片
            photoRepository.Insert(photo);
            this.UploadPhoto(photo, file);
            photoRepository.Update(photo);

            //更新相册PhotoCount,LastUploadDate
            album.PhotoCount++;
            album.LastUploadDate = photo.DateCreated;
            albumRepository.Update(album);

            //用户内容计数OwnerData+1
            OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());

            ownerDataService.Change(photo.UserId, OwnerDataKeys.Instance().PhotoCount(), 1);

            //处理积分动态
            EventBus <Album> .Instance().OnAfter(album, new CommonEventArgs(EventOperationType.Instance().Create()));

            EventBus <Album, AuditEventArgs> .Instance().OnAfter(album, new AuditEventArgs(null, photo.AuditStatus));

            EventBus <Photo, AuditEventArgs> .Instance().OnAfter(photo, new AuditEventArgs(null, photo.AuditStatus));

            EventBus <Photo> .Instance().OnAfter(photo, new CommonEventArgs(EventOperationType.Instance().Create()));

            return(photo.PhotoId > 0);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// 删除回复贴
        /// </summary>
        /// <param name="postId">回复贴Id</param>
        public void Delete(long postId)
        {
            BarPost post = barPostRepository.Get(postId);

            if (post == null)
            {
                return;
            }
            BarSectionService barSectionService = new BarSectionService();
            BarSection        barSection        = barSectionService.Get(post.SectionId);

            if (barSection == null)
            {
                return;
            }
            EventBus <BarPost> .Instance().OnBefore(post, new CommonEventArgs(EventOperationType.Instance().Delete()));

            int affectCount = barPostRepository.Delete(post);

            if (affectCount > 0)
            {
                //更新帖吧的计数
                CountService countService = new CountService(TenantTypeIds.Instance().BarSection());
                countService.ChangeCount(CountTypes.Instance().ThreadAndPostCount(), barSection.SectionId, barSection.UserId, -1 - post.ChildPostCount, true);
                if (post.TenantTypeId == TenantTypeIds.Instance().Group())
                {
                    //群组内容计数-1
                    OwnerDataService groupOwnerDataService = new OwnerDataService(TenantTypeIds.Instance().Group());
                    groupOwnerDataService.Change(post.SectionId, OwnerDataKeys.Instance().PostCount(), -1);
                }
                else if (post.TenantTypeId == TenantTypeIds.Instance().Bar())
                {
                    //用户内容计数-1
                    OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                    ownerDataService.Change(post.UserId, OwnerDataKeys.Instance().PostCount(), -1);
                }

                EventBus <BarPost> .Instance().OnAfter(post, new CommonEventArgs(EventOperationType.Instance().Delete()));

                EventBus <BarPost, AuditEventArgs> .Instance().OnAfter(post, new AuditEventArgs(post.AuditStatus, null));
            }
        }
 //todo:mazq,by zhengw:走查以下代码:用户关注帖吧时,要追溯该帖吧的动态
 /// <summary>
 /// 关注帖吧事件处理程序
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="eventArgs"></param>
 void SubscribeBarSectionEventModule_After(long sender, SubscribeEventArgs eventArgs)
 {
     if (eventArgs.TenantTypeId != TenantTypeIds.Instance().BarSection())
         return;
     ActivityService activityService = new ActivityService();
     if (EventOperationType.Instance().Create() == eventArgs.EventOperationType)
     {
         activityService.TraceBackInboxAboutOwner(eventArgs.UserId, sender, ActivityOwnerTypes.Instance().BarSection());
         //用户内容计数
         OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
         ownerDataService.Change(eventArgs.UserId, OwnerDataKeys.Instance().FollowSectionCount(), 1);
     }
     else if (EventOperationType.Instance().Delete() == eventArgs.EventOperationType)
     {
         activityService.RemoveInboxAboutOwner(eventArgs.UserId, sender, ActivityOwnerTypes.Instance().BarSection());
         //用户内容计数
         OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
         ownerDataService.Change(eventArgs.UserId, OwnerDataKeys.Instance().FollowSectionCount(), -1);
     }
 }
Ejemplo n.º 24
0
        /// <summary>
        /// 移除群组成员
        /// </summary>
        /// <param name="groupId">群组Id</param>
        /// <param name="userId">用户Id</param>
        public void DeleteGroupMember(long groupId, long userId)
        {
            GroupMember groupMember = groupMemberRepository.GetMember(groupId, userId);

            if (groupMember == null)
            {
                return;
            }

            int affectCount = groupMemberRepository.Delete(groupMember);

            if (affectCount > 0)
            {
                EventBus <GroupMember> .Instance().OnAfter(groupMember, new CommonEventArgs(EventOperationType.Instance().Delete()));

                //用户的参与群组数-1
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(userId, OwnerDataKeys.Instance().JoinedGroupCount(), -1);
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// 发布回答
        /// </summary>
        /// <remarks>
        /// 1.每个回答者针对每个问题只能回答一次,创建回答前需做重复检查
        /// 2.注意维护相关问题的回答数,AnswerCount++
        /// 3.注意需要在EventModule中处理动态、积分、通知、自动关注(回答者自动关注该问题)
        /// 4.注意使用AuditService.ChangeAuditStatusForCreate设置审核状态;
        /// 5.注意调用AttachmentService转换临时附件;
        /// 6.需要触发的事件:1)Create的OnBefore、OnAfter;2)审核状态变更;
        /// </remarks>
        /// <param name="answer">回答实体</param>
        /// <returns>是否创建成功</returns>
        public bool CreateAnswer(AskAnswer answer)
        {
            //先查询当前用户是否已经回答了指定问题
            if (GetUserAnswerByQuestionId(answer.UserId, answer.QuestionId) == null)
            {
                EventBus <AskAnswer> .Instance().OnBefore(answer, new CommonEventArgs(EventOperationType.Instance().Create()));

                //设置审核状态
                new AuditService().ChangeAuditStatusForCreate(answer.UserId, answer);

                askAnswerRepository.Insert(answer);

                if (answer.AnswerId > 0)
                {
                    //维护相关问题的内容
                    AskQuestion question = askQuestionRepository.Get(answer.QuestionId);
                    question.LastAnswerUserId = answer.UserId;
                    question.LastAnswerAuthor = answer.Author;
                    question.LastAnswerDate   = answer.DateCreated;
                    question.AnswerCount++;

                    //调用Service中的Update方法,以触发相应的事件,但是不更新审核状态
                    this.UpdateQuestion(question, false);

                    //将临时附件转换为正式附件
                    AttachmentService attachmentService = new AttachmentService(TenantTypeIds.Instance().AskAnswer());
                    attachmentService.ToggleTemporaryAttachments(answer.UserId, TenantTypeIds.Instance().AskAnswer(), answer.AnswerId);

                    //用户回答数计数
                    OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                    ownerDataService.Change(answer.UserId, OwnerDataKeys.Instance().AnswerCount(), 1);

                    EventBus <AskAnswer> .Instance().OnAfter(answer, new CommonEventArgs(EventOperationType.Instance().Create()));

                    EventBus <AskAnswer, AuditEventArgs> .Instance().OnAfter(answer, new AuditEventArgs(null, answer.AuditStatus));
                }
            }

            return(answer.AnswerId > 0);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// 创建ContentItem
        /// </summary>
        /// <param name="contentItem"></param>
        public void Create(ContentItem contentItem)
        {
            //设置审核状态
            if (contentItem.IsContributed && contentItem.ContentFolder != null && contentItem.ContentFolder.NeedAuditing)
            {
                new AuditService().ChangeAuditStatusForCreate(contentItem.UserId, contentItem);
            }
            else
            {
                contentItem.AuditStatus = AuditStatus.Success;
            }

            //执行事件
            EventBus <ContentItem> .Instance().OnBefore(contentItem, new CommonEventArgs(EventOperationType.Instance().Create()));

            contentItemRepository.Insert(contentItem);
            //转换临时附件
            AttachmentService attachmentService = new AttachmentService(TenantTypeIds.Instance().ContentItem());

            attachmentService.ToggleTemporaryAttachments(contentItem.UserId, TenantTypeIds.Instance().ContentItem(), contentItem.ContentItemId);
            if (contentItem.AdditionalProperties.Get <bool>("FirstAsTitleImage", false))
            {
                IEnumerable <Attachment> attachments = new AttachmentService(TenantTypeIds.Instance().ContentItem()).GetsByAssociateId(contentItem.ContentItemId);
                Attachment fristImage = attachments.Where(n => n.MediaType == MediaType.Image).FirstOrDefault();
                if (fristImage != null)
                {
                    contentItem.FeaturedImageAttachmentId = fristImage.AttachmentId;
                    contentItem.FeaturedImage             = fristImage.GetRelativePath() + "\\" + fristImage.FileName;
                }
            }
            //用户投稿计数+1
            OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());

            ownerDataService.Change(contentItem.UserId, OwnerDataKeys.Instance().ContributeCount(), 1);
            //执行事件
            EventBus <ContentItem> .Instance().OnAfter(contentItem, new CommonEventArgs(EventOperationType.Instance().Create(), ApplicationIds.Instance().CMS()));

            EventBus <ContentItem, AuditEventArgs> .Instance().OnAfter(contentItem, new AuditEventArgs(null, contentItem.AuditStatus));
        }
Ejemplo n.º 27
0
        /// <summary>
        /// 创建群组
        /// </summary>
        /// <param name="userId">当前操作人</param>
        /// <param name="group"><see cref="GroupEntity"/></param>
        /// <param name="logoFile">群组标识图</param>
        /// <returns>创建成功返回true,失败返回false</returns>
        public bool Create(long userId, GroupEntity group)
        {
            //设计要点
            //1、使用AuditService设置审核状态;
            //2、需要触发的事件参见《设计说明书-日志》     
            //3、单独调用标签服务设置标签
            //4、使用 IdGenerator.Next() 生成GroupId
            EventBus<GroupEntity>.Instance().OnBefore(group, new CommonEventArgs(EventOperationType.Instance().Create()));
            //设置审核状态
            auditService.ChangeAuditStatusForCreate(userId, group);
            long id = 0;
            long.TryParse(groupRepository.Insert(group).ToString(), out id);

            if (id > 0)
            {
                EventBus<GroupEntity>.Instance().OnAfter(group, new CommonEventArgs(EventOperationType.Instance().Create()));
                EventBus<GroupEntity, AuditEventArgs>.Instance().OnAfter(group, new AuditEventArgs(null, group.AuditStatus));
                //用户的创建群组数+1
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(group.UserId, OwnerDataKeys.Instance().CreatedGroupCount(), 1);
            }
            return id > 0;
        }
Ejemplo n.º 28
0
        /// <summary>
        /// 关注帖吧事件处理程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        void SubscribeBarSectionEventModule_After(long sender, SubscribeEventArgs eventArgs)
        {
            if (eventArgs.TenantTypeId != TenantTypeIds.Instance().BarSection())
            {
                return;
            }
            ActivityService activityService = new ActivityService();

            if (EventOperationType.Instance().Create() == eventArgs.EventOperationType)
            {
                activityService.TraceBackInboxAboutOwner(eventArgs.UserId, sender, ActivityOwnerTypes.Instance().BarSection());
                //用户内容计数
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(eventArgs.UserId, OwnerDataKeys.Instance().FollowSectionCount(), 1);
            }
            else if (EventOperationType.Instance().Delete() == eventArgs.EventOperationType)
            {
                activityService.RemoveInboxAboutOwner(eventArgs.UserId, sender, ActivityOwnerTypes.Instance().BarSection());
                //用户内容计数
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(eventArgs.UserId, OwnerDataKeys.Instance().FollowSectionCount(), -1);
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// 删除词条
        /// </summary>
        /// <param name="wikiPage">词条实体</param>
        public void Delete(WikiPage wikiPage)
        {
            if (wikiPage == null)
            {
                return;
            }

            //todo:zhengw:需要处理词条版本

            CategoryService categoryService = new CategoryService();

            //删除站点分类关联(投稿到)
            categoryService.ClearCategoriesFromItem(wikiPage.PageId, 0, TenantTypeIds.Instance().WikiPage());

            //删除标签关联
            TagService tagService = new TagService(TenantTypeIds.Instance().WikiPage());

            tagService.ClearTagsFromItem(wikiPage.PageId, wikiPage.OwnerId);

            //删除推荐记录
            RecommendService recommendService = new RecommendService();

            recommendService.Delete(wikiPage.PageId, wikiPage.TenantTypeId);

            //用户创建词条数-1
            OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());

            ownerDataService.Change(wikiPage.UserId, OwnerDataKeys.Instance().PageCount(), -1);

            EventBus <WikiPage> .Instance().OnBefore(wikiPage, new CommonEventArgs(EventOperationType.Instance().Delete()));

            wikiPageRepository.Delete(wikiPage);

            EventBus <WikiPage> .Instance().OnAfter(wikiPage, new CommonEventArgs(EventOperationType.Instance().Delete()));

            EventBus <WikiPage, AuditEventArgs> .Instance().OnAfter(wikiPage, new AuditEventArgs(wikiPage.AuditStatus, null));
        }
Ejemplo n.º 30
0
        /// <summary>
        /// 删除群组
        /// </summary>
        /// <param name="groupId">群组Id</param>
        public void Delete(long groupId)
        {
            //设计要点
            //1、需要删除:群组成员、群组申请、Logo;
            GroupEntity group = groupRepository.Get(groupId);

            if (group == null)
            {
                return;
            }

            CategoryService categoryService = new CategoryService();

            categoryService.ClearCategoriesFromItem(groupId, null, TenantTypeIds.Instance().Group());


            EventBus <GroupEntity> .Instance().OnBefore(group, new CommonEventArgs(EventOperationType.Instance().Delete()));

            int affectCount = groupRepository.Delete(group);

            if (affectCount > 0)
            {
                //删除访客记录
                new VisitService(TenantTypeIds.Instance().Group()).CleanByToObjectId(groupId);
                //用户的创建群组数-1
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(group.UserId, OwnerDataKeys.Instance().CreatedGroupCount(), -1);
                //删除Logo
                LogoService logoService = new LogoService(TenantTypeIds.Instance().Group());
                logoService.DeleteLogo(groupId);
                //删除群组下的成员
                DeleteMembersByGroupId(groupId);
                EventBus <GroupEntity> .Instance().OnAfter(group, new CommonEventArgs(EventOperationType.Instance().Delete()));

                EventBus <GroupEntity, AuditEventArgs> .Instance().OnAfter(group, new AuditEventArgs(group.AuditStatus, null));
            }
        }
Ejemplo n.º 31
0
        /// <summary>
        /// 删除ContentItem
        /// </summary>
        /// <param name="contentItem"></param>
        public void Delete(ContentItem contentItem)
        {
            if (contentItem != null)
            {
                //执行事件
                EventBus <ContentItem> .Instance().OnBefore(contentItem, new CommonEventArgs(EventOperationType.Instance().Delete()));

                contentItemRepository.Delete(contentItem);
                //用户投稿计数-1
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(contentItem.UserId, OwnerDataKeys.Instance().ContributeCount(), -1);

                //删除标签关联
                TagService tagService = new TagService(TenantTypeIds.Instance().ContentItem());
                tagService.ClearTagsFromItem(contentItem.ContentItemId, contentItem.UserId);
                //删除评论
                CommentService commentService = new CommentService();
                commentService.DeleteCommentedObjectComments(contentItem.ContentItemId);
                //执行事件
                EventBus <ContentItem> .Instance().OnAfter(contentItem, new CommonEventArgs(EventOperationType.Instance().Delete(), ApplicationIds.Instance().CMS()));

                EventBus <ContentItem, AuditEventArgs> .Instance().OnAfter(contentItem, new AuditEventArgs(contentItem.AuditStatus, null));
            }
        }
Ejemplo n.º 32
0
        /// <summary>
        /// 删除问题
        /// </summary>
        /// <remarks>
        /// 1.只有管理员可删除问题,已解决问题的积分不返还,未解决的问题应该解除冻结积分,通过EventModule处理;
        /// 2.注意需要删除动态,通过EventModule处理;
        /// 3.注意需要扣除发布问题时增加的积分,通过EventModule处理;
        /// 4.注意需要删除所有用户对该问题的关注,通过EventModule处理;
        /// 5.注意删除与标签的关联,其它数据的删除由各模块自动处理
        /// 6.需要触发的事件:1)Delete的OnBefore、OnAfter;2)审核状态变更
        /// </remarks>
        /// <param name="question">问题实体</param>
        public void DeleteQuestion(AskQuestion question)
        {
            EventBus <AskQuestion> .Instance().OnBefore(question, new CommonEventArgs(EventOperationType.Instance().Delete()));

            //删除与标签的关联
            TagService tagService = new TagService(TenantTypeIds.Instance().AskQuestion());

            tagService.ClearTagsFromItem(question.QuestionId, question.UserId);

            //删除问题的所有回答
            int pageSize  = 100;
            int pageIndex = 1;
            int pageCount = 1;

            do
            {
                PagingDataSet <AskAnswer> answers = this.GetAnswersByQuestionId(question.QuestionId, SortBy_AskAnswer.DateCreated_Desc, pageSize, pageIndex);
                foreach (AskAnswer answer in answers)
                {
                    this.DeleteAnswer(answer);
                }
                pageCount = answers.PageCount;
                pageIndex++;
            } while (pageIndex <= pageCount);

            //删除问题
            askQuestionRepository.Delete(question);

            OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());

            ownerDataService.Change(question.UserId, OwnerDataKeys.Instance().QuestionCount(), -1);

            EventBus <AskQuestion> .Instance().OnAfter(question, new CommonEventArgs(EventOperationType.Instance().Delete()));

            EventBus <AskQuestion, AuditEventArgs> .Instance().OnAfter(question, new AuditEventArgs(question.AuditStatus, null));
        }
Ejemplo n.º 33
0
        /// <summary>
        /// 创建主题帖
        /// </summary>
        /// <param name="thread">主题帖</param>
        public bool Create(BarThread thread)
        {
            BarSectionService barSectionService = new BarSectionService();
            EventBus<BarThread>.Instance().OnBefore(thread, new CommonEventArgs(EventOperationType.Instance().Create()));
            //设置审核状态
            auditService.ChangeAuditStatusForCreate(thread.UserId, thread);
            long id = 0;
            long.TryParse(barThreadRepository.Insert(thread).ToString(), out id);

            if (id > 0)
            {
                new AttachmentService(TenantTypeIds.Instance().BarThread()).ToggleTemporaryAttachments(thread.UserId, TenantTypeIds.Instance().BarThread(), id);
                BarSection barSection = barSectionService.Get(thread.SectionId);
                if (barSection != null)
                {
                    //计数
                    CountService countService = new CountService(TenantTypeIds.Instance().BarSection());
                    countService.ChangeCount(CountTypes.Instance().ThreadCount(), barSection.SectionId, barSection.UserId, 1, true);
                    countService.ChangeCount(CountTypes.Instance().ThreadAndPostCount(), barSection.SectionId, barSection.UserId, 1, true);
                    if (thread.TenantTypeId == TenantTypeIds.Instance().Group())
                    {
                        //群组内容计数+1
                        OwnerDataService groupOwnerDataService = new OwnerDataService(TenantTypeIds.Instance().Group());
                        groupOwnerDataService.Change(thread.SectionId, OwnerDataKeys.Instance().ThreadCount(), 1);
                    }
                }
                if (thread.TenantTypeId == TenantTypeIds.Instance().Bar())
                {
                    //用户内容计数+1
                    OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                    ownerDataService.Change(thread.UserId, OwnerDataKeys.Instance().ThreadCount(), 1);
                }
                AtUserService atUserService = new AtUserService(TenantTypeIds.Instance().BarThread());
                atUserService.ResolveBodyForEdit(thread.GetBody(), thread.UserId, thread.ThreadId);

                EventBus<BarThread>.Instance().OnAfter(thread, new CommonEventArgs(EventOperationType.Instance().Create()));
                EventBus<BarThread, AuditEventArgs>.Instance().OnAfter(thread, new AuditEventArgs(null, thread.AuditStatus));
            }
            return id > 0;
        }
Ejemplo n.º 34
0
        /// <summary>
        /// 删除微博
        /// </summary>
        /// <param name="microblogId">微博Id</param>
        public void Delete(long microblogId)
        {
            MicroblogEntity entity = Get(microblogId);
            if (entity == null)
                return;

            var sender = new CommentService().GetCommentedObjectComments(microblogId);

            EventBus<MicroblogEntity>.Instance().OnBefore(entity, new CommonEventArgs(EventOperationType.Instance().Delete()));
            int affect = microblogRepository.Delete(entity);
            if (affect > 0)
            {
                //删除微博时评论的积分处理
                if (sender != null)
                    EventBus<Comment>.Instance().OnBatchAfter(sender, new CommonEventArgs(EventOperationType.Instance().Delete()));
                //更新用户数据
                OwnerDataService ownerDataService = new OwnerDataService(entity.TenantTypeId);
                ownerDataService.Change(entity.OwnerId, OwnerDataKeys.Instance().ThreadCount(), -1);

                EventBus<MicroblogEntity>.Instance().OnAfter(entity, new CommonEventArgs(EventOperationType.Instance().Delete()));
                EventBus<MicroblogEntity, AuditEventArgs>.Instance().OnAfter(entity, new AuditEventArgs(entity.AuditStatus, null));
            }
        }
        /// <summary>
        /// 增加专题成员
        /// </summary>
        /// <param name="TopicMember"></param>
        public void CreateTopicMember(TopicMember TopicMember)
        {
            //设计要点:
            //1、同一个专题不允许用户重复加入
            //2、群主不允许成为专题成员
            if (IsMember(TopicMember.TopicId, TopicMember.UserId))
                return;
            if (IsOwner(TopicMember.TopicId, TopicMember.UserId))
                return;
            long id = 0;
            long.TryParse(TopicMemberRepository.Insert(TopicMember).ToString(), out id);

            if (id > 0)
            {
                EventBus<TopicMember>.Instance().OnAfter(TopicMember, new CommonEventArgs(EventOperationType.Instance().Create()));
                //用户的参与专题数+1
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(TopicMember.UserId, OwnerDataKeys.Instance().JoinedTopicCount(), 1);
            }
        }
Ejemplo n.º 36
0
        /// <summary>
        /// 删除群组
        /// </summary>
        /// <param name="groupId">群组Id</param>
        public void Delete(long groupId)
        {
            //设计要点
            //1、需要删除:群组成员、群组申请、Logo;
            GroupEntity group = groupRepository.Get(groupId);
            if (group == null)
                return;

            CategoryService categoryService = new CategoryService();
            categoryService.ClearCategoriesFromItem(groupId, null, TenantTypeIds.Instance().Group());


            EventBus<GroupEntity>.Instance().OnBefore(group, new CommonEventArgs(EventOperationType.Instance().Delete()));
            int affectCount = groupRepository.Delete(group);
            if (affectCount > 0)
            {
                //删除访客记录
                new VisitService(TenantTypeIds.Instance().Group()).CleanByToObjectId(groupId);
                //用户的创建群组数-1
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(group.UserId, OwnerDataKeys.Instance().CreatedGroupCount(), -1);
                //删除Logo             
                LogoService logoService = new LogoService(TenantTypeIds.Instance().Group());
                logoService.DeleteLogo(groupId);
                //删除群组下的成员
                DeleteMembersByGroupId(groupId);
                EventBus<GroupEntity>.Instance().OnAfter(group, new CommonEventArgs(EventOperationType.Instance().Delete()));
                EventBus<GroupEntity, AuditEventArgs>.Instance().OnAfter(group, new AuditEventArgs(group.AuditStatus, null));
            }
        }
Ejemplo n.º 37
0
        /// <summary>
        /// 更换群主
        /// </summary>
        /// <param name="groupId">群组Id</param>
        /// <param name="newOwnerUserId">新群主UserId</param>
        public void ChangeGroupOwner(long groupId, long newOwnerUserId)
        {
            //更换群主后,原群主转换成群组成员,如果新群主是群组成员则从成员中移除
            GroupEntity group = groupRepository.Get(groupId);
            long oldOwnerUserId = group.UserId;
            group.UserId = newOwnerUserId;
            groupRepository.ChangeGroupOwner(groupId, newOwnerUserId);

            //原群主的群组数-1,加入群组数+1
            OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
            ownerDataService.Change(oldOwnerUserId, OwnerDataKeys.Instance().CreatedGroupCount(), -1);
            ownerDataService.Change(oldOwnerUserId, OwnerDataKeys.Instance().JoinedGroupCount(), 1);

            //原群主转换成群组成员
            GroupMember groupMember = GroupMember.New();
            groupMember.GroupId = groupId;
            groupMember.UserId = oldOwnerUserId;
            groupMemberRepository.Insert(groupMember);

            //新群主的群组数+1,加入群组数-1
            ownerDataService.Change(newOwnerUserId, OwnerDataKeys.Instance().CreatedGroupCount(), 1);

            //如果新群主是群组成员则从成员中移除
            if (IsMember(groupId, newOwnerUserId))
                DeleteGroupMember(groupId, newOwnerUserId);
        }
Ejemplo n.º 38
0
        /// <summary>
        /// 删除主题帖
        /// </summary>
        /// <param name="threadId">主题帖Id</param>
        public void Delete(long threadId)
        {
            BarThread thread = barThreadRepository.Get(threadId);
            if (thread == null)
                return;

            EventBus<BarThread>.Instance().OnBefore(thread, new CommonEventArgs(EventOperationType.Instance().Delete()));

            BarSectionService barSectionService = new BarSectionService();
            BarSection barSection = barSectionService.Get(thread.SectionId);
            if (barSection != null)
            {
                //帖子标签
                TagService tagService = new TagService(TenantTypeIds.Instance().BarThread());
                tagService.ClearTagsFromItem(threadId, barSection.SectionId);

                //帖子分类
                CategoryService categoryService = new CategoryService();
                categoryService.ClearCategoriesFromItem(threadId, barSection.SectionId, TenantTypeIds.Instance().BarThread());
            }

            //删除回帖
            BarPostService barPostService = new BarPostService();
            barPostService.DeletesByThreadId(threadId);

            //删除推荐记录
            RecommendService recommendService = new RecommendService();
            recommendService.Delete(threadId, TenantTypeIds.Instance().BarThread());

            int affectCount = barThreadRepository.Delete(thread);

            if (affectCount > 0)
            {
                //更新帖吧的计数
                CountService countService = new CountService(TenantTypeIds.Instance().BarSection());
                countService.ChangeCount(CountTypes.Instance().ThreadCount(), barSection.SectionId, barSection.UserId, -1, true);
                countService.ChangeCount(CountTypes.Instance().ThreadAndPostCount(), barSection.SectionId, barSection.UserId, -1, true);

                if (thread.TenantTypeId == TenantTypeIds.Instance().Group())
                {
                    //群组内容计数-1
                    OwnerDataService groupOwnerDataService = new OwnerDataService(TenantTypeIds.Instance().Group());
                    groupOwnerDataService.Change(thread.SectionId, OwnerDataKeys.Instance().ThreadCount(), -1);
                }
                else if (thread.TenantTypeId == TenantTypeIds.Instance().Bar())
                {
                    //用户内容计数-1
                    OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                    ownerDataService.Change(thread.UserId, OwnerDataKeys.Instance().ThreadCount(), -1);
                }
                EventBus<BarThread>.Instance().OnAfter(thread, new CommonEventArgs(EventOperationType.Instance().Delete()));
                EventBus<BarThread, AuditEventArgs>.Instance().OnAfter(thread, new AuditEventArgs(thread.AuditStatus, null));
            }

            //BarThread删除可能影响的:
            //1、附件 (看到了)
            //2、BarPost(看到了)
            //3、BarRating(看到了)
            //4、相关计数对象(看到了)
            //5、用户在应用中的数据(看到了)
            //6、@用户(看到了)
        }
        /// <summary>
        /// 更换群主
        /// </summary>
        /// <param name="groupId">专题Id</param>
        /// <param name="newOwnerUserId">新群主UserId</param>
        public void ChangeTopicOwner(long groupId, long newOwnerUserId)
        {
            //更换群主后,原群主转换成专题成员,如果新群主是专题成员则从成员中移除
            TopicEntity group = topicRepository.Get(groupId);
            long oldOwnerUserId = group.UserId;
            group.UserId = newOwnerUserId;
            topicRepository.ChangeTopicOwner(groupId, newOwnerUserId);

            //原群主的专题数-1,加入专题数+1
            OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
            ownerDataService.Change(oldOwnerUserId, OwnerDataKeys.Instance().CreatedTopicCount(), -1);
            ownerDataService.Change(oldOwnerUserId, OwnerDataKeys.Instance().JoinedTopicCount(), 1);

            //原群主转换成专题成员
            TopicMember TopicMember = TopicMember.New();
            TopicMember.TopicId = groupId;
            TopicMember.UserId = oldOwnerUserId;
            TopicMemberRepository.Insert(TopicMember);

            //新群主的专题数+1,加入专题数-1
            ownerDataService.Change(newOwnerUserId, OwnerDataKeys.Instance().CreatedTopicCount(), 1);

            //如果新群主是专题成员则从成员中移除
            if (IsMember(groupId, newOwnerUserId))
                DeleteTopicMember(groupId, newOwnerUserId);
        }
Ejemplo n.º 40
0
        /// <summary>
        /// 增加群组成员
        /// </summary>
        /// <param name="groupMember"></param>
        public void CreateGroupMember(GroupMember groupMember)
        {
            //设计要点:
            //1、同一个群组不允许用户重复加入
            //2、群主不允许成为群组成员
            if (IsMember(groupMember.GroupId, groupMember.UserId))
                return;
            if (IsOwner(groupMember.GroupId, groupMember.UserId))
                return;
            long id = 0;
            long.TryParse(groupMemberRepository.Insert(groupMember).ToString(), out id);

            if (id > 0)
            {
                EventBus<GroupMember>.Instance().OnAfter(groupMember, new CommonEventArgs(EventOperationType.Instance().Create()));
                //用户的参与群组数+1
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(groupMember.UserId, OwnerDataKeys.Instance().JoinedGroupCount(), 1);
            }
        }
Ejemplo n.º 41
0
        /// <summary>
        /// 移除群组成员
        /// </summary>
        /// <param name="groupId">群组Id</param>
        /// <param name="userId">用户Id</param>
        public void DeleteGroupMember(long groupId, long userId)
        {



            GroupMember groupMember = groupMemberRepository.GetMember(groupId, userId);
            if (groupMember == null)
                return;

            int affectCount = groupMemberRepository.Delete(groupMember);
            if (affectCount > 0)
            {
                EventBus<GroupMember>.Instance().OnAfter(groupMember, new CommonEventArgs(EventOperationType.Instance().Delete()));
                //用户的参与群组数-1
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(userId, OwnerDataKeys.Instance().JoinedGroupCount(), -1);
            }
        }
Ejemplo n.º 42
0
 /// <summary>
 /// 删除群组下的成员
 /// </summary>
 /// <param name="groupId"></param>
 public void DeleteMembersByGroupId(long groupId)
 {
     IEnumerable<GroupMember> groupMembers = groupMemberRepository.GetAllMembersOfGroup(groupId);
     foreach (var groupMember in groupMembers)
     {
         int affectCount = groupMemberRepository.Delete(groupMember);
         if (affectCount > 0)
         {
             EventBus<GroupMember>.Instance().OnAfter(groupMember, new CommonEventArgs(EventOperationType.Instance().Delete()));
             //用户的参与群组数-1
             OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
             ownerDataService.Change(groupMember.UserId, OwnerDataKeys.Instance().JoinedGroupCount(), -1);
         }
     }
 }
Ejemplo n.º 43
0
        /// <summary>
        /// 创建微博
        /// </summary>
        /// <param name="microblog">待创建微博实体</param>
        /// <returns></returns>
        public long Create(MicroblogEntity microblog)
        {
            EventBus<MicroblogEntity>.Instance().OnBefore(microblog, new CommonEventArgs(EventOperationType.Instance().Create()));

            //设置审核状态
            auditService.ChangeAuditStatusForCreate(microblog.UserId, microblog);

            string videoAlias = string.Empty, audioAlias = string.Empty;

            microblog.Body = parsedMediaService.ResolveBodyForEdit(microblog.Body, out videoAlias, out audioAlias);
            microblog.HasVideo = !string.IsNullOrEmpty(videoAlias);
            microblog.HasMusic = !string.IsNullOrEmpty(audioAlias);
            microblog.VideoAlias = videoAlias;
            microblog.AudioAlias = audioAlias;

            long id = 0;
            long.TryParse(microblogRepository.Insert(microblog).ToString(), out id);

            if (id > 0)
            {
                string tenantTypeId = TenantTypeIds.Instance().Microblog();

                OwnerDataService ownerDataService = new OwnerDataService(microblog.TenantTypeId);
                ownerDataService.Change(microblog.OwnerId, OwnerDataKeys.Instance().ThreadCount(), 1);

                //将临时附件转换为正式附件
                attachmentService.ToggleTemporaryAttachments(microblog.UserId, tenantTypeId, id);

                AtUserService atUserService = new AtUserService(tenantTypeId);
                atUserService.ResolveBodyForEdit(microblog.Body, microblog.UserId, microblog.MicroblogId);

                TagService tagService = new TagService(tenantTypeId);
                tagService.ResolveBodyForEdit(microblog.Body, microblog.OwnerId, microblog.MicroblogId, tenantTypeId);

                EventBus<MicroblogEntity>.Instance().OnAfter(microblog, new CommonEventArgs(EventOperationType.Instance().Create()));
                EventBus<MicroblogEntity, AuditEventArgs>.Instance().OnAfter(microblog, new AuditEventArgs(null, microblog.AuditStatus));
            }

            return id;
        }