Beispiel #1
0
        /// <summary>
        /// 取消关注日志操作
        /// </summary>
        public JsonResult _SubscribeCancel(string spaceKey, long threadId)
        {
            if (UserContext.CurrentUser == null)
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, "必须先登录,才能继续操作")));
            }

            long userId = UserContext.CurrentUser.UserId;

            if (!subscribeService.IsSubscribed(threadId, userId))
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, "您没有关注过该日志")));
            }

            BlogThread blogThread = blogService.Get(threadId);

            if (blogThread == null)
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, "找不到要被关注的日志")));
            }

            subscribeService.CancelSubscribe(threadId, userId);

            return(Json(new StatusMessageData(StatusMessageType.Success, "取消关注操作成功")));
        }
Beispiel #2
0
        /// <summary>
        /// 帖吧申请处理结果通知
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        void BarSectionNoticeEventModule_After(BarSection sender, CommonEventArgs eventArgs)
        {
            if (eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved())
            {
                IUserService  userService   = DIContainer.Resolve <IUserService>();
                NoticeService noticeService = DIContainer.Resolve <NoticeService>();
                User          toUser        = userService.GetFullUser(sender.UserId);
                if (toUser == null)
                {
                    return;
                }
                Notice notice = Notice.New();
                notice.UserId             = sender.UserId;
                notice.ApplicationId      = BarConfig.Instance().ApplicationId;
                notice.TypeId             = NoticeTypeIds.Instance().Reply();
                notice.LeadingActorUserId = sender.UserId;
                notice.LeadingActor       = toUser.DisplayName;
                notice.LeadingActorUrl    = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(toUser.UserName));
                notice.RelativeObjectId   = sender.SectionId;
                notice.RelativeObjectName = HtmlUtility.TrimHtml(sender.Name, 64);
                if (eventArgs.EventOperationType == EventOperationType.Instance().Approved())
                {
                    //通知吧主,其申请的帖吧通过了审核
                    notice.TemplateName = NoticeTemplateNames.Instance().ManagerApproved();
                }
                else
                {
                    //通知吧主,其申请的帖吧未通过审核
                    notice.TemplateName = NoticeTemplateNames.Instance().ManagerDisapproved();
                }

                notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().SectionDetail(sender.SectionId));
                noticeService.Create(notice);
            }
            else if (eventArgs.EventOperationType == EventOperationType.Instance().Delete())
            {
                SubscribeService   subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());
                IEnumerable <long> userIds          = subscribeService.GetTopUserIdsOfObject(sender.SectionId, int.MaxValue);

                foreach (long userId in userIds)
                {
                    subscribeService.CancelSubscribe(sender.SectionId, userId);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 问题增删改等触发的事件
        /// </summary>
        private void AskQuestionEventModule_After(AskQuestion question, CommonEventArgs eventArgs)
        {
            if (eventArgs.EventOperationType == EventOperationType.Instance().Create())
            {
                //冻结用户的积分
                if (question.AddedReward > 0)
                {
                    userService.FreezeTradePoints(question.UserId, question.AddedReward);
                }

                //向定向提问的目标用户发送通知
                if (question.AskUserId > 0)
                {
                    Notice notice = Notice.New();
                    notice.UserId             = question.AskUserId;
                    notice.ApplicationId      = AskConfig.Instance().ApplicationId;
                    notice.TypeId             = NoticeTypeIds.Instance().Hint();
                    notice.LeadingActor       = question.Author;
                    notice.LeadingActorUrl    = SiteUrls.FullUrl(SiteUrls.Instance().AskUser(UserIdToUserNameDictionary.GetUserName(question.UserId)));
                    notice.RelativeObjectName = HtmlUtility.TrimHtml(question.Subject, 64);
                    notice.RelativeObjectUrl  = SiteUrls.FullUrl(SiteUrls.Instance().AskQuestionDetail(question.QuestionId));
                    notice.TemplateName       = NoticeTemplateNames.Instance().AskUser();
                    noticeService.Create(notice);
                }

                //自动关注(提问者自动关注[订阅]该问题)
                if (!subscribeService.IsSubscribed(question.QuestionId, question.UserId))
                {
                    subscribeService.Subscribe(question.QuestionId, question.UserId);

                    //问题关注数计数,用于“可能感兴趣的问题”关联表查询
                    countService.ChangeCount(CountTypes.Instance().QuestionFollowerCount(), question.QuestionId, question.UserId, 1, false);
                }
            }
            else if (eventArgs.EventOperationType == EventOperationType.Instance().Delete())
            {
                //已解决问题的积分不返还,未解决/已取消的问题应该解除冻结积分
                if (question.Reward > 0 && question.Status != QuestionStatus.Resolved)
                {
                    userService.UnfreezeTradePoints(question.UserId, question.Reward);
                }

                //删除所有用户对该问题的关注(订阅)
                IEnumerable <long> userIds = subscribeService.GetUserIdsOfObject(question.QuestionId);
                foreach (var userId in userIds)
                {
                    subscribeService.CancelSubscribe(question.QuestionId, userId);
                }
            }
            else if (eventArgs.EventOperationType == EventOperationType.Instance().Update())
            {
                //冻结用户的积分
                if (question.AddedReward != 0)
                {
                    userService.FreezeTradePoints(question.UserId, question.AddedReward);
                }
                if (question.Status == QuestionStatus.Canceled)
                {
                    subscribeService.CancelSubscribe(question.QuestionId, question.UserId);
                    int pageSize = 100;
                    for (int i = 1; i <= question.AnswerCount; i = i + pageSize)
                    {
                        PagingDataSet <AskAnswer> answers = askService.GetAnswersByQuestionId(question.QuestionId, SortBy_AskAnswer.DateCreated_Desc, pageSize, i);
                        foreach (AskAnswer answer in answers)
                        {
                            subscribeService.CancelSubscribe(question.QuestionId, answer.UserId);
                        }
                    }
                }
            }
            //加精时处理积分和威望并产生通知
            else if (eventArgs.EventOperationType == EventOperationType.Instance().SetEssential())
            {
                string pointItemKey = PointItemKeys.Instance().EssentialContent();
                string description  = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventArgs.EventOperationType), "问题", question.Subject);
                pointService.GenerateByRole(question.UserId, pointItemKey, description);

                if (question.UserId > 0)
                {
                    Notice notice = Notice.New();
                    notice.UserId             = question.UserId;
                    notice.ApplicationId      = AskConfig.Instance().ApplicationId;
                    notice.TypeId             = NoticeTypeIds.Instance().Hint();
                    notice.LeadingActor       = question.Author;
                    notice.LeadingActorUrl    = SiteUrls.FullUrl(SiteUrls.Instance().AskUser(UserIdToUserNameDictionary.GetUserName(question.UserId)));
                    notice.RelativeObjectName = HtmlUtility.TrimHtml(question.Subject, 64);
                    notice.RelativeObjectUrl  = SiteUrls.FullUrl(SiteUrls.Instance().AskQuestionDetail(question.QuestionId));
                    notice.TemplateName       = NoticeTemplateNames.Instance().ManagerSetEssential();
                    noticeService.Create(notice);
                }
                //记录用户的威望
                PointItem pointItem = pointService.GetPointItem(pointItemKey);
                ownerDataService.Change(question.UserId, OwnerDataKeys.Instance().UserAskReputation(), pointItem.ReputationPoints);
            }
        }