示例#1
0
文件: Authorizer.cs 项目: hbulzy/SYS
        /// <summary>
        /// 是否具有评分的权限
        /// </summary>
        /// <returns></returns>
        public static bool BarRating(this Authorizer authorizer, BarThread thread, out string errorMessage)
        {
            BarSettings barSettings = DIContainer.Resolve<ISettingsManager<BarSettings>>().Get();
            errorMessage = "没有找到对应的帖子";
            if (thread == null)
                return false;
            errorMessage = "您还没有登录";
            IUser currentUser = UserContext.CurrentUser;
            if (currentUser == null)
                return false;

            if (thread.UserId == currentUser.UserId)
            {
                errorMessage = "您不可以给自己的帖子评分哦";
                return false;
            }

            BarRatingService barRatingService = new BarRatingService();
            //是否已经评过分
            errorMessage = "您已经评论过此贴";
            if (barRatingService.IsRated(currentUser.UserId, thread.ThreadId))
                return false;
            errorMessage = "您的剩余积分不够了哦";
            if (barRatingService.GetUserTodayRatingSum(UserContext.CurrentUser.UserId) + barSettings.ReputationPointsMinValue > barSettings.UserReputationPointsPerDay)
                return false;

            ISettingsManager<BarSettings> barSettingsManager = DIContainer.Resolve<ISettingsManager<BarSettings>>();
            BarSettings barSetting = barSettingsManager.Get();
            BarSectionService barSectionService = new BarSectionService();
            var barSection = barSectionService.Get(thread.SectionId);
            if (barSection == null)
                return false;
            if (barSection.TenantTypeId == TenantTypeIds.Instance().Bar())
            {

                errorMessage = "此帖吧仅允许关注的用户评分哦";
                if (barSetting.OnlyFollowerCreatePost)
                {
                    SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());
                    return subscribeService.IsSubscribed(thread.SectionId, currentUser.UserId);
                }
            }
            else
            {
                if (authorizer.AuthorizationService.IsTenantMember(currentUser, barSection.TenantTypeId, barSection.SectionId))
                    return true;
            }

            errorMessage = "站点没有开启帖子评分";
            if (!barSetting.EnableRating)
                return false;
            return true;
        }
示例#2
0
        /// <summary>
        /// 是否具有评分的权限
        /// </summary>
        /// <returns></returns>
        public static bool BarRating(this Authorizer authorizer, BarThread thread, out string errorMessage)
        {
            BarSettings barSettings = DIContainer.Resolve <IBarSettingsManager>().Get();

            errorMessage = "没有找到对应的帖子";
            if (thread == null)
            {
                return(false);
            }
            errorMessage = "您还没有登录";
            IUser currentUser = UserContext.CurrentUser;

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

            if (thread.UserId == currentUser.UserId)
            {
                errorMessage = "您不可以给自己的帖子评分哦";
                return(false);
            }

            BarRatingService barRatingService = new BarRatingService();

            //是否已经评过分
            errorMessage = "您已经评论过此贴";
            if (barRatingService.IsRated(currentUser.UserId, thread.ThreadId))
            {
                return(false);
            }
            errorMessage = "您的剩余积分不够了哦";
            if (barRatingService.GetUserTodayRatingSum(UserContext.CurrentUser.UserId) + barSettings.ReputationPointsMinValue > barSettings.UserReputationPointsPerDay)
            {
                return(false);
            }

            IBarSettingsManager barSettingsManager = DIContainer.Resolve <IBarSettingsManager>();
            BarSettings         barSetting         = barSettingsManager.Get();
            BarSectionService   barSectionService  = new BarSectionService();
            var barSection = barSectionService.Get(thread.SectionId);

            if (barSection == null)
            {
                return(false);
            }
            if (barSection.TenantTypeId == TenantTypeIds.Instance().Bar())
            {
                errorMessage = "此帖吧仅允许关注的用户评分哦";
                if (barSetting.OnlyFollowerCreatePost)
                {
                    SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());
                    return(subscribeService.IsSubscribed(thread.SectionId, currentUser.UserId));
                }
            }
            else
            {
                if (authorizer.AuthorizationService.IsTenantMember(currentUser, barSection.TenantTypeId, barSection.SectionId))
                {
                    return(true);
                }
            }

            errorMessage = "站点没有开启帖子评分";
            if (!barSetting.EnableRating)
            {
                return(false);
            }
            return(true);
        }