Exemple #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);
            }
        }
Exemple #2
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));
        }
Exemple #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);
            }
        }
Exemple #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));
            }
        }
Exemple #5
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);
        }
Exemple #6
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);
            }
        }
Exemple #7
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);
            }
        }
Exemple #8
0
        /// <summary>
        /// 应用加载
        /// </summary>
        public override void Load()
        {
            base.Load();
            //注册帖吧计数服务
            CountService countService = new CountService(TenantTypeIds.Instance().BarSection());

            countService.RegisterCounts();      //注册计数服务
            countService.RegisterCountPerDay(); //需要统计阶段计数时,需注册每日计数服务
            countService.RegisterStageCount(CountTypes.Instance().ThreadAndPostCount(), 1);
            //注册帖子计数服务
            countService = new CountService(TenantTypeIds.Instance().BarThread());
            countService.RegisterCounts();      //注册计数服务
            countService.RegisterCountPerDay(); //需要统计阶段计数时,需注册每日计数服务
            countService.RegisterStageCount(CountTypes.Instance().HitTimes(), 1, 7);


            //注册贴吧用户计数服务
            List <string> tenantTypeIds = new List <string>()
            {
                TenantTypeIds.Instance().User(), TenantTypeIds.Instance().Group()
            };

            OwnerDataSettings.RegisterStatisticsDataKeys(tenantTypeIds
                                                         , OwnerDataKeys.Instance().ThreadCount()
                                                         , OwnerDataKeys.Instance().PostCount()
                                                         , OwnerDataKeys.Instance().FollowSectionCount());

            TagUrlGetterManager.RegisterGetter(TenantTypeIds.Instance().BarThread(), new BarTagUrlGetter());
            TagUrlGetterManager.RegisterGetter(TenantTypeIds.Instance().Group(), new BarTagUrlGetter());
            //添加应用管理员角色
            ApplicationAdministratorRoleNames.Add(ApplicationIds.Instance().Bar(), new List <string> {
                "BarAdministrator"
            });
        }
Exemple #9
0
        /// <summary>
        /// 应用加载
        /// </summary>
        public override void Load()
        {
            base.Load();

            //注册价格设置
            PriceSetting.RegisterSettings(this.priceSettingElement);

            //注册商品的计数服务
            CountService countService = new CountService(TenantTypeIds.Instance().PointGift());

            countService.RegisterCounts();

            //注册申请计数服务
            List <string> tenantTypeIds = new List <string>()
            {
                TenantTypeIds.Instance().User(), TenantTypeIds.Instance().Group()
            };

            OwnerDataSettings.RegisterStatisticsDataKeys(tenantTypeIds, OwnerDataKeys.Instance().PostCount());

            //添加应用管理员角色
            ApplicationAdministratorRoleNames.Add(applicationId, new List <string> {
                "PointMallAdministrator"
            });
        }
Exemple #10
0
        /// <summary>
        /// 应用加载
        /// </summary>
        public override void Load()
        {
            base.Load();

            //注册日志Rss浏览计数服务
            CountService countService = new CountService(TenantTypeIds.Instance().Microblog());

            countService.RegisterCounts();      //注册计数服务
            countService.RegisterCountPerDay(); //需要统计阶段计数时,需注册每日计数服务
            countService.RegisterStageCount(CountTypes.Instance().CommentCount(), 1);

            //注册微博用户计数服务
            List <string> tenantTypeIds = new List <string>()
            {
                TenantTypeIds.Instance().User(), TenantTypeIds.Instance().Group()
            };

            OwnerDataSettings.RegisterStatisticsDataKeys(tenantTypeIds, OwnerDataKeys.Instance().ThreadCount());

            TagUrlGetterManager.RegisterGetter(TenantTypeIds.Instance().Microblog(), new MicroblogTagUrlGetter());

            //添加应用管理员角色
            ApplicationAdministratorRoleNames.Add(ApplicationIds.Instance().Microblog(), new List <string> {
                "MicroblogAdministrator"
            });
        }
Exemple #11
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);
            }
        }
Exemple #12
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);
        }
Exemple #13
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);
            }
        }
Exemple #14
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);
        }
Exemple #15
0
        /// <summary>
        /// 获取用户是否接受定向提问
        /// </summary>
        /// <param name="userId">用户id</param>
        /// <returns>是否接受定向提问</returns>
        public bool IsAcceptQuestion(long userId)
        {
            OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());

            string accept = ownerDataService.GetString(userId, OwnerDataKeys.Instance().AcceptQuestion());

            return(string.IsNullOrEmpty(accept) ? false : bool.Parse(accept));
        }
Exemple #16
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()));
            }
        }
Exemple #17
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);
        }
Exemple #18
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));
        }
Exemple #19
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);
        }
Exemple #20
0
        /// <summary>
        /// 获取问答用户统计数据
        /// </summary>
        /// <remarks>
        /// 需统计:问题数、回答数、回答被采纳数、赞同数
        /// 无需缓存
        /// </remarks>
        /// <param name="userId">用户id</param>
        /// <returns>用户统计数据</returns>
        public Dictionary <string, long> GetUserStatisticData(long userId)
        {
            OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());

            Dictionary <string, long> userStatisticData = new Dictionary <string, long>();

            userStatisticData.Add(OwnerDataKeys.Instance().QuestionCount(), ownerDataService.GetLong(userId, OwnerDataKeys.Instance().QuestionCount()));
            userStatisticData.Add(OwnerDataKeys.Instance().AnswerCount(), ownerDataService.GetLong(userId, OwnerDataKeys.Instance().AnswerCount()));
            userStatisticData.Add(OwnerDataKeys.Instance().AnswerAcceptCount(), ownerDataService.GetLong(userId, OwnerDataKeys.Instance().AnswerAcceptCount()));
            userStatisticData.Add(OwnerDataKeys.Instance().AnswerSupportCount(), ownerDataService.GetLong(userId, OwnerDataKeys.Instance().AnswerSupportCount()));
            userStatisticData.Add(OwnerDataKeys.Instance().UserAskReputation(), ownerDataService.GetLong(userId, OwnerDataKeys.Instance().UserAskReputation()));

            return(userStatisticData);
        }
        /// <summary>
        /// 用户排行列表
        /// </summary>
        public ActionResult _UserRank(int topNum = 5)
        {
            IEnumerable <long>      userIds         = ownerDataService.GetTopOwnerIds(OwnerDataKeys.Instance().ThreadCount(), topNum, OwnerData_SortBy.LongValue_DESC);
            IEnumerable <IUser>     users           = userService.GetFullUsers(userIds);
            Dictionary <long, long> userThreadCount = new Dictionary <long, long>();

            foreach (long userId in userIds)
            {
                //用户日志数
                long threadCount = ownerDataService.GetLong(userId, OwnerDataKeys.Instance().ThreadCount());
                userThreadCount[userId] = threadCount;
            }

            ViewData["userThreadCount"] = userThreadCount;
            return(View(users));
        }
Exemple #22
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);
                }
            }
        }
Exemple #23
0
        /// <summary>
        /// 用户空间日志左侧控制面板
        /// </summary>
        /// <param name="menu">菜单项标识</param>
        public ActionResult _Panel(string spaceKey, string menu = null)
        {
            User user = userService.GetFullUser(spaceKey);
            ViewData["user"] = user;

            //用户日志数
            long threadCount = ownerDataService.GetLong(user.UserId, OwnerDataKeys.Instance().ThreadCount());
            ViewData["threadCount"] = threadCount;

            IUser currentUser = UserContext.CurrentUser;
            if (currentUser != null && currentUser.UserId != user.UserId)
            {
                bool followed = new FollowService().IsFollowed(currentUser.UserId, user.UserId);
                ViewData["followed"] = followed;
            }

            return View();
        }
Exemple #24
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);
            }
        }
Exemple #25
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);
        }
Exemple #26
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);
        }
Exemple #27
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);
        }
Exemple #28
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);
        }
Exemple #29
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));
            }
        }
Exemple #30
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);
            }
        }