コード例 #1
0
ファイル: Authorizer.cs プロジェクト: yaotyl/spb4mono
        /// <summary>
        /// 是否具有编辑BarThread的权限
        /// </summary>
        /// <param name="threadId"></param>
        /// <returns></returns>
        public static bool BarThread_Edit(this Authorizer authorizer, BarThread thread)
        {
            if (thread == null)
            {
                return(false);
            }

            BarSection section = thread.BarSection;

            if (section != null && section.AuditStatus == AuditStatus.Success)
            {
                if (UserContext.CurrentUser == null)
                {
                    return(false);
                }
                if (thread.UserId == UserContext.CurrentUser.UserId)
                {
                    return(true);
                }
            }

            BarSectionService barSectionService = new BarSectionService();

            if (authorizer.BarSection_Manage(barSectionService.Get(thread.SectionId)))
            {
                return(true);
            }

            return(false);
        }
コード例 #2
0
ファイル: BarThreadService.cs プロジェクト: x1987624/SNS
        /// <summary>
        /// 移动帖子
        /// </summary>
        /// <param name="threadId">要移动帖子的ThreadId</param>
        /// <param name="moveToSectionId">转移到帖吧的SectionId</param>
        public void MoveThread(long threadId, long moveToSectionId)
        {
            BarThread thread = barThreadRepository.Get(threadId);

            if (thread.SectionId == moveToSectionId)
            {
                return;
            }
            long oldSectionId      = thread.SectionId;
            var  barSectionService = new BarSectionService();
            var  oldSection        = barSectionService.Get(oldSectionId);

            if (oldSection == null)
            {
                return;
            }
            var newSection = barSectionService.Get(moveToSectionId);

            if (newSection == null)
            {
                return;
            }
            barThreadRepository.MoveThread(threadId, moveToSectionId);

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

            countService.ChangeCount(CountTypes.Instance().ThreadCount(), oldSection.SectionId, oldSection.UserId, -1, true);
            countService.ChangeCount(CountTypes.Instance().ThreadAndPostCount(), oldSection.SectionId, oldSection.UserId, -1, true);

            countService.ChangeCount(CountTypes.Instance().ThreadCount(), newSection.SectionId, newSection.UserId, 1, true);
            countService.ChangeCount(CountTypes.Instance().ThreadAndPostCount(), newSection.SectionId, newSection.UserId, 1, true);
        }
コード例 #3
0
 /// <summary>
 /// 贴吧详细页面地址
 /// </summary>
 /// <param name="itemId">推荐内容Id</param>
 /// <returns></returns>
 public string RecommendItemDetail(long itemId)
 {
     BarSection barSection = new BarSectionService().Get(itemId);
     if (barSection == null)
         return string.Empty;
     return SiteUrls.Instance().SectionDetail(itemId);
 }
コード例 #4
0
        private void AuthorizeCore(AuthorizationContext filterContext)
        {
            string spaceKey  = UserContext.CurrentSpaceKey(filterContext);
            long   sectionId = filterContext.RequestContext.GetParameterFromRouteDataOrQueryString <long>("sectionId");

            if (sectionId == 0)
            {
                throw new ExceptionFacade("sectionId为0");
            }
            BarSectionService barSectionService = new BarSectionService();
            BarSection        section           = barSectionService.Get(sectionId);

            if (section == null)
            {
                throw new ExceptionFacade("找不到当前帖吧");
            }
            if (section.IsEnabled)
            {
                return;
            }
            if (DIContainer.Resolve <Authorizer>().BarSection_Manage(section))
            {
                return;
            }

            filterContext.Result = new RedirectResult(SiteUrls.Instance().SystemMessage(filterContext.Controller.TempData, new SystemMessageViewModel
            {
                Title             = "帖吧未启用",
                Body              = "您访问的帖吧未启用,暂时不允许访问",
                StatusMessageType = StatusMessageType.Hint
            }) /* 跳向无权访问页 */);
        }
コード例 #5
0
ファイル: BarThreadService.cs プロジェクト: x1987624/SNS
        /// <summary>
        /// 删除用户记录(删除用户时使用)
        /// </summary>
        /// <param name="userId">被删除用户</param>
        /// <param name="takeOverUserName">接管用户名</param>
        /// <param name="takeOverAll">是否接管被删除用户的所有内容</param>
        public void DeleteUser(long userId, string takeOverUserName, bool takeOverAll)
        {
            long              takeOverUserId    = UserIdToUserNameDictionary.GetUserId(takeOverUserName);
            IUserService      userService       = DIContainer.Resolve <IUserService>();
            User              takeOver          = userService.GetFullUser(takeOverUserId);
            BarSectionService barSectionService = new BarSectionService();
            BarThreadService  barThreadService  = new BarThreadService();
            BarPostService    barPostService    = new BarPostService();

            //删除用户时,不删除贴吧,把贴吧转让,如果没有指定转让人,那就转给网站初始管理员
            if (takeOver == null)
            {
                takeOverUserId = new SystemDataService().GetLong("Founder");
                takeOver       = userService.GetFullUser(takeOverUserId);
            }

            barThreadRepository.DeleteUser(userId, takeOver, takeOverAll);
            if (takeOver != null)
            {
                if (!takeOverAll)
                {
                    barThreadService.DeletesByUserId(userId);
                    barPostService.DeletesByUserId(userId);
                }
            }
            //else
            //{
            //    barSectionService.DeletesByUserId(userId);
            //    barThreadService.DeletesByUserId(userId);
            //    barPostService.DeletesByUserId(userId);
            //}
        }
コード例 #6
0
ファイル: Authorizer.cs プロジェクト: yaotyl/spb4mono
        /// <summary>
        /// 是否具有编辑BarPost的权限
        /// </summary>
        /// <param name="post"></param>
        /// <returns></returns>
        public static bool BarPost_Edit(this Authorizer authorizer, BarPost post)
        {
            if (authorizer.IsAdministrator(BarConfig.Instance().ApplicationId))
            {
                return(true);
            }

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

            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }
            if (post.UserId == currentUser.UserId)
            {
                return(true);
            }
            BarSectionService barSectionService = new BarSectionService();

            if (authorizer.BarSection_Manage(barSectionService.Get(post.SectionId)))
            {
                return(true);
            }

            return(false);
        }
コード例 #7
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);
        }
コード例 #8
0
        /// <summary>
        /// 是否拥有logo
        /// </summary>
        /// <returns>是否拥有图表</returns>
        public bool HasLogoImage()
        {
            BarSection section = new BarSectionService().Get(this.SectionId);

            if (section != null)
            {
                return(section.HasLogoImage);
            }
            return(false);
        }
コード例 #9
0
        /// <summary>
        /// 贴吧详细页面地址
        /// </summary>
        /// <param name="itemId">推荐内容Id</param>
        /// <returns></returns>
        public string RecommendItemDetail(long itemId)
        {
            BarSection barSection = new BarSectionService().Get(itemId);

            if (barSection == null)
            {
                return(string.Empty);
            }
            return(SiteUrls.Instance().SectionDetail(itemId));
        }
コード例 #10
0
ファイル: Authorizer.cs プロジェクト: yaotyl/spb4mono
        /// <summary>
        /// 是否具有管理BarThread的权限
        /// </summary>
        /// <param name="threadId"></param>
        /// <returns></returns>
        public static bool BarThread_Manage(this Authorizer authorizer, BarThread thread)
        {
            if (thread == null)
            {
                return(false);
            }

            BarSectionService barSectionService = new BarSectionService();

            return(authorizer.BarSection_Manage(barSectionService.Get(thread.SectionId)));
        }
コード例 #11
0
        /// <summary>
        /// 获取前台编辑的实体
        /// </summary>
        /// <returns>获取前台编辑的实体</returns>
        public BarSection GetBarSectionByEditForManager()
        {
            BarSection section = new BarSectionService().Get(this.SectionId);

            if (section == null)
            {
                return(null);
            }
            section.Description          = this.Description;
            section.ThreadCategoryStatus = this.ThreadCategoryStatus;
            return(section);
        }
コード例 #12
0
ファイル: BarSectionEventModule.cs プロジェクト: hbulzy/SYS
        /// <summary>
        /// 贴吧所在呈现区域拥有者自动创建贴吧事件
        /// </summary>
        /// <param name="sender">群组实体</param>
        /// <param name="eventArgs">事件参数</param>
        void AutoMaintainBarSectionModule_After(GroupEntity sender, CommonEventArgs eventArgs)
        {
            BarSectionService barSectionService = new BarSectionService();
            if (eventArgs.EventOperationType == EventOperationType.Instance().Create())
            {

                BarSection barSection = BarSection.New();

                barSection.TenantTypeId = TenantTypeIds.Instance().Group();
                barSection.SectionId = sender.GroupId;
                barSection.OwnerId = sender.GroupId;
                barSection.UserId = sender.UserId;
                barSection.Name = sender.GroupName;
                barSection.IsEnabled = true;
                barSection.LogoImage = sender.Logo;
                barSection.ThreadCategoryStatus = ThreadCategoryStatus.NotForceEnabled;
                barSectionService.Create(barSection, sender.UserId, null, null);
            }
            else if (eventArgs.EventOperationType == EventOperationType.Instance().Update())
            {
                BarSection barSection = barSectionService.Get(sender.GroupId);
                barSection.UserId = sender.UserId;
                barSection.Name = sender.GroupName;
                barSection.LogoImage = sender.Logo;

                IList<long> managerIds = null;
                if (barSection.SectionManagers != null)
                {
                    managerIds = barSection.SectionManagers.Select(n => n.UserId).ToList();
                }
                barSectionService.Update(barSection, sender.UserId, managerIds, null);
            }
            else if (eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved())
            {
                BarSection barSection = barSectionService.Get(sender.GroupId);
                barSection.AuditStatus = sender.AuditStatus;
                IList<long> managerIds = null;
                if (barSection.SectionManagers != null)
                {
                    managerIds = barSection.SectionManagers.Select(n => n.UserId).ToList();
                }
                barSectionService.Update(barSection, sender.UserId, managerIds, null);
            }
            else
            {
                barSectionService.Delete(sender.GroupId);
            }
        }
コード例 #13
0
ファイル: BarThreadService.cs プロジェクト: x1987624/SNS
        /// <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);
        }
コード例 #14
0
        /// <summary>
        /// 将ViewModel转换成数据库存储实体
        /// </summary>
        /// <returns></returns>
        public BarThread AsBarThread()
        {
            BarThreadService  barThreadService  = new BarThreadService();
            BarSectionService barSectionService = new BarSectionService();

            BarThread barThread = null;

            if (this.ThreadId > 0)
            {
                barThread = barThreadService.Get(this.ThreadId);
            }
            else
            {
                barThread        = BarThread.New();
                barThread.UserId = UserContext.CurrentUser.UserId;
                barThread.Author = UserContext.CurrentUser.DisplayName;
            }
            if (barThread == null)
            {
                return(barThread);
            }
            barThread.SectionId = this.SectionId;
            if (this.StickyDate.CompareTo(DateTime.UtcNow) > 0)
            {
                barThread.StickyDate = this.StickyDate;
            }
            barThread.Subject      = this.Subject;
            barThread.Body         = this.Body;
            barThread.IsHidden     = this.IsHidden;
            barThread.IsEssential  = this.IsEssential;
            barThread.IsSticky     = this.IsSticky;
            barThread.LastModified = DateTime.UtcNow;
            barThread.TenantTypeId = TenantTypeIds.Instance().Bar();

            BarSection barSection = barSectionService.Get(this.SectionId);

            if (barSection != null)
            {
                barThread.OwnerId      = barSection.OwnerId;
                barThread.TenantTypeId = barSection.TenantTypeId;
            }
            return(barThread);
        }
コード例 #15
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));
            }
        }
コード例 #16
0
        /// <summary>
        /// 将ViewModel转换成数据库存储实体
        /// </summary>
        /// <returns></returns>
        public BarSection AsBarSection()
        {
            BarSectionService barSectionService = new BarSectionService();

            BarSection barSection = null;

            if (this.SectionId > 0)
            {
                barSection = barSectionService.Get(this.SectionId);
            }
            else
            {
                barSection = BarSection.New();
                barSection.TenantTypeId = TenantTypeIds.Instance().Bar();
            }
            barSection.Name                 = this.Name;
            barSection.Description          = this.Description;
            barSection.IsEnabled            = this.IsEnabled;
            barSection.ThreadCategoryStatus = this.ThreadCategoryStatus;
            return(barSection);
        }
コード例 #17
0
ファイル: Authorizer.cs プロジェクト: hbulzy/SYS
        /// <summary>
        /// 是否具有创建BarPost的权限
        /// </summary>
        /// <param name="sectionId">所属帖吧Id</param>
        /// <returns></returns>
        public static bool BarPost_Create(this Authorizer authorizer, long sectionId, out string errorMessage)
        {
            IUser currentUser = UserContext.CurrentUser;
            errorMessage = "没有权限回帖";
            BarSectionService barSectionService = new BarSectionService();
            var barSection = barSectionService.Get(sectionId);
            if (barSection == null)
                return false;

            if (barSection.AuditStatus != AuditStatus.Success)
            {
                errorMessage = "由于贴吧未经过审核,所以不允许发帖";
                return false;
            }

            if (!authorizer.AuthorizationService.Check(currentUser, PermissionItemKeys.Instance().Bar_CreatePost()))
            {
                if (currentUser != null && currentUser.IsModerated)
                    errorMessage = Resources.Resource.Description_ModeratedUser_CreateBarPostDenied;
                return false;
            }

            if (barSection.TenantTypeId == TenantTypeIds.Instance().Bar())
            {
                //检查是否需要是关注用户才能发帖
                ISettingsManager<BarSettings> barSettingsManager = DIContainer.Resolve<ISettingsManager<BarSettings>>();
                BarSettings barSetting = barSettingsManager.Get();
                if (barSetting.OnlyFollowerCreatePost)
                {
                    if (currentUser == null)
                    {
                        errorMessage = "您需要先登录并关注此帖吧,才能回帖";
                        return false;
                    }
                    SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());
                    bool isSubscribed = subscribeService.IsSubscribed(sectionId, currentUser.UserId);
                    if (!isSubscribed)
                        errorMessage = "您需要先关注此帖吧,才能回帖";
                    return isSubscribed;
                }
            }
            else
            {
                if (authorizer.BarSection_Manage(barSection))
                    return true;
                bool isTenantMember = authorizer.AuthorizationService.IsTenantMember(currentUser, barSection.TenantTypeId, barSection.SectionId);
                if (!isTenantMember)
                    errorMessage = "您需要先加入,才能回帖";
                return isTenantMember;
            }

            //站点设置是否启用了匿名发帖
            ISettingsManager<SiteSettings> siteSettingsManager = DIContainer.Resolve<ISettingsManager<SiteSettings>>();
            SiteSettings siteSettings = siteSettingsManager.Get();
            if (siteSettings.EnableAnonymousPosting)
                return true;

            if (currentUser == null)
            {
                errorMessage = "您必须先登录,才能回帖";
                return false;
            }
            return true;
        }
コード例 #18
0
ファイル: Authorizer.cs プロジェクト: hbulzy/SYS
        /// <summary>
        /// 是否具有编辑BarThread的权限
        /// </summary>
        /// <param name="threadId"></param>
        /// <returns></returns>
        public static bool BarThread_Edit(this Authorizer authorizer, BarThread thread)
        {
            if (thread == null)
                return false;

            BarSection section = thread.BarSection;
            if (section != null && section.AuditStatus == AuditStatus.Success)
            {
                if (UserContext.CurrentUser == null)
                    return false;
                if (thread.UserId == UserContext.CurrentUser.UserId)
                    return true;
            }

            BarSectionService barSectionService = new BarSectionService();
            if (authorizer.BarSection_Manage(barSectionService.Get(thread.SectionId)))
                return true;

            return false;
        }
コード例 #19
0
ファイル: Authorizer.cs プロジェクト: hbulzy/SYS
        /// <summary>
        /// 是否具有管理BarThread的权限
        /// </summary>
        /// <param name="threadId"></param>
        /// <returns></returns>
        public static bool BarThread_Manage(this Authorizer authorizer, BarThread thread)
        {
            if (thread == null)
                return false;

            BarSectionService barSectionService = new BarSectionService();
            return authorizer.BarSection_Manage(barSectionService.Get(thread.SectionId));
        }
コード例 #20
0
ファイル: Authorizer.cs プロジェクト: hbulzy/SYS
 /// <summary>
 /// 是否具有管理BarSection的权限
 /// </summary>
 /// <param name="authorizer"></param>
 /// <param name="barSectionId"></param>
 /// <returns></returns>
 public static bool BarSection_Manage(this Authorizer authorizer, long barSectionId)
 {
     BarSection section = new BarSectionService().Get(barSectionId);
     return BarSection_Manage(authorizer, section);
 }
コード例 #21
0
ファイル: Authorizer.cs プロジェクト: hbulzy/SYS
        /// <summary>
        /// 是否具有创建BarThread的权限
        /// </summary>
        /// <param name="authorizer"></param>
        /// <param name="sectionId">所属帖吧Id</param>
        /// <param name="errorMessage">无权信息提示</param>
        /// <returns></returns>
        public static bool BarThread_Create(this Authorizer authorizer, long sectionId, out string errorMessage)
        {
            errorMessage = string.Empty;
            IUser currentUser = UserContext.CurrentUser;
            if (currentUser == null)
            {
                errorMessage = "您需要先登录,才能发帖";
                return false;
            }
            BarSectionService barSectionService = new BarSectionService();
            var barSection = barSectionService.Get(sectionId);
            if (barSection == null)
            {
                errorMessage = "贴吧不存在";
                return false;
            }

            if (authorizer.BarSection_Manage(barSection))
                return true;

            if (!authorizer.AuthorizationService.Check(currentUser, PermissionItemKeys.Instance().Bar_CreateThread()))
            {
                if (currentUser.IsModerated)
                    errorMessage = Resources.Resource.Description_ModeratedUser_CreateBarThreadDenied;
                return false;
            }
            if (barSection.TenantTypeId == TenantTypeIds.Instance().Bar())
            {
                ISettingsManager<BarSettings> barSettingsManager = DIContainer.Resolve<ISettingsManager<BarSettings>>();
                BarSettings barSetting = barSettingsManager.Get();
                if (barSetting.OnlyFollowerCreateThread)
                {
                    SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());
                    if (subscribeService.IsSubscribed(sectionId, currentUser.UserId))
                        return true;
                    else
                    {
                        errorMessage = "您需要先关注此帖吧,才能发帖";
                        return false;
                    }
                }
                else
                    return true;
            }
            else
            {
                if (authorizer.AuthorizationService.IsTenantMember(currentUser, barSection.TenantTypeId, barSection.SectionId))
                    return true;
                else
                {
                    TenantType tenantType = new TenantTypeService().Get(barSection.TenantTypeId);
                    errorMessage = string.Format("只有加入{0}才能发帖", tenantType.Name);
                    return false;
                }
            }
        }
コード例 #22
0
ファイル: Authorizer.cs プロジェクト: hbulzy/SYS
        /// <summary>
        /// 是否具有编辑BarPost的权限
        /// </summary>
        /// <param name="post"></param>
        /// <returns></returns>
        public static bool BarPost_Edit(this Authorizer authorizer, BarPost post)
        {
            if (authorizer.IsAdministrator(BarConfig.Instance().ApplicationId))
                return true;

            if (post == null)
                return false;

            IUser currentUser = UserContext.CurrentUser;
            if (currentUser == null)
                return false;
            if (post.UserId == currentUser.UserId)
                return true;
            BarSectionService barSectionService = new BarSectionService();
            if (authorizer.BarSection_Manage(barSectionService.Get(post.SectionId)))
                return true;

            return false;
        }
コード例 #23
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;
        }
コード例 #24
0
ファイル: BarThreadService.cs プロジェクト: x1987624/SNS
        /// <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、@用户(看到了)
        }
コード例 #25
0
ファイル: BarSectionEditModel.cs プロジェクト: hbulzy/SYS
 /// <summary>
 /// 是否拥有logo
 /// </summary>
 /// <returns>是否拥有图表</returns>
 public bool HasLogoImage()
 {
     BarSection section = new BarSectionService().Get(this.SectionId);
     if (section != null)
         return section.HasLogoImage;
     return false;
 }
コード例 #26
0
        /// <summary>
        /// 删除用户记录(删除用户时使用)
        /// </summary>
        /// <param name="userId">被删除用户</param>
        /// <param name="takeOverUserName">接管用户名</param>
        /// <param name="takeOverAll">是否接管被删除用户的所有内容</param>
        public void DeleteUser(long userId, string takeOverUserName, bool takeOverAll)
        {
            long takeOverUserId = UserIdToUserNameDictionary.GetUserId(takeOverUserName);
            IUserService userService = DIContainer.Resolve<IUserService>();
            User takeOver = userService.GetFullUser(takeOverUserId);
            BarSectionService barSectionService = new BarSectionService();
            BarThreadService barThreadService = new BarThreadService();
            BarPostService barPostService = new BarPostService();

            //删除用户时,不删除贴吧,把贴吧转让,如果没有指定转让人,那就转给网站初始管理员
            if (takeOver == null)
            {
                takeOverUserId = new SystemDataService().GetLong("Founder");
                takeOver = userService.GetFullUser(takeOverUserId);
            }

            barThreadRepository.DeleteUser(userId, takeOver, takeOverAll);
            if (takeOver != null)
            {
                if (!takeOverAll)
                {
                    barThreadService.DeletesByUserId(userId);
                    barPostService.DeletesByUserId(userId);
                }
            }
            //else
            //{
            //    barSectionService.DeletesByUserId(userId);
            //    barThreadService.DeletesByUserId(userId);
            //    barPostService.DeletesByUserId(userId);
            //}
        }
コード例 #27
0
ファイル: Authorizer.cs プロジェクト: yaotyl/spb4mono
        /// <summary>
        /// 是否具有管理BarSection的权限
        /// </summary>
        /// <param name="authorizer"></param>
        /// <param name="barSectionId"></param>
        /// <returns></returns>
        public static bool BarSection_Manage(this Authorizer authorizer, long barSectionId)
        {
            BarSection section = new BarSectionService().Get(barSectionId);

            return(BarSection_Manage(authorizer, section));
        }
コード例 #28
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;
        }
コード例 #29
0
        /// <summary>
        /// 移动帖子
        /// </summary>
        /// <param name="threadId">要移动帖子的ThreadId</param>
        /// <param name="moveToSectionId">转移到帖吧的SectionId</param>
        public void MoveThread(long threadId, long moveToSectionId)
        {
            BarThread thread = barThreadRepository.Get(threadId);
            if (thread.SectionId == moveToSectionId)
                return;
            long oldSectionId = thread.SectionId;
            var barSectionService = new BarSectionService();
            var oldSection = barSectionService.Get(oldSectionId);
            if (oldSection == null)
                return;
            var newSection = barSectionService.Get(moveToSectionId);
            if (newSection == null)
                return;
            barThreadRepository.MoveThread(threadId, moveToSectionId);

            CountService countService = new CountService(TenantTypeIds.Instance().BarSection());
            countService.ChangeCount(CountTypes.Instance().ThreadCount(), oldSection.SectionId, oldSection.UserId, -1, true);
            countService.ChangeCount(CountTypes.Instance().ThreadAndPostCount(), oldSection.SectionId, oldSection.UserId, -1, true);

            countService.ChangeCount(CountTypes.Instance().ThreadCount(), newSection.SectionId, newSection.UserId, 1, true);
            countService.ChangeCount(CountTypes.Instance().ThreadAndPostCount(), newSection.SectionId, newSection.UserId, 1, true);
        }
コード例 #30
0
ファイル: BarSectionEditModel.cs プロジェクト: hbulzy/SYS
 /// <summary>
 /// 获取前台编辑的实体
 /// </summary>
 /// <returns>获取前台编辑的实体</returns>
 public BarSection GetBarSectionByEditForManager()
 {
     BarSection section = new BarSectionService().Get(this.SectionId);
     if (section == null)
         return null;
     section.Description = this.Description;
     section.ThreadCategoryStatus = this.ThreadCategoryStatus;
     return section;
 }
コード例 #31
0
        /// <summary>
        /// 将ViewModel转换成数据库存储实体
        /// </summary>
        /// <returns></returns>
        public BarThread AsBarThread()
        {
            BarThreadService barThreadService = new BarThreadService();
            BarSectionService barSectionService = new BarSectionService();

            BarThread barThread = null;
            if (this.ThreadId > 0)
            {
                barThread = barThreadService.Get(this.ThreadId);

            }
            else
            {
                barThread = BarThread.New();
                barThread.UserId = UserContext.CurrentUser.UserId;
                barThread.Author = UserContext.CurrentUser.DisplayName;
            }
            if (barThread == null)
                return barThread;
            barThread.SectionId = this.SectionId;
            if (this.StickyDate.CompareTo(DateTime.UtcNow) > 0)
                barThread.StickyDate = this.StickyDate;
            barThread.Subject = this.Subject;
            barThread.Body = this.Body;
            barThread.IsHidden = this.IsHidden;
            barThread.IsEssential = this.IsEssential;
            barThread.IsSticky = this.IsSticky;
            barThread.LastModified = DateTime.UtcNow;
            barThread.TenantTypeId = TenantTypeIds.Instance().Bar();

            BarSection barSection = barSectionService.Get(this.SectionId);
            if (barSection != null)
            {
                barThread.OwnerId = barSection.OwnerId;
                barThread.TenantTypeId = barSection.TenantTypeId;
            }
            return barThread;
        }
コード例 #32
0
ファイル: Authorizer.cs プロジェクト: yaotyl/spb4mono
        /// <summary>
        /// 是否具有创建BarPost的权限
        /// </summary>
        /// <param name="sectionId">所属帖吧Id</param>
        /// <returns></returns>
        public static bool BarPost_Create(this Authorizer authorizer, long sectionId, out string errorMessage)
        {
            IUser currentUser = UserContext.CurrentUser;

            errorMessage = "没有权限回帖";
            BarSectionService barSectionService = new BarSectionService();
            var barSection = barSectionService.Get(sectionId);

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

            if (barSection.AuditStatus != AuditStatus.Success)
            {
                errorMessage = "由于贴吧未经过审核,所以不允许发帖";
                return(false);
            }

            if (!authorizer.AuthorizationService.Check(currentUser, PermissionItemKeys.Instance().Bar_CreatePost()))
            {
                if (currentUser != null && currentUser.IsModerated)
                {
                    errorMessage = Resources.Resource.Description_ModeratedUser_CreateBarPostDenied;
                }
                return(false);
            }

            if (barSection.TenantTypeId == TenantTypeIds.Instance().Bar())
            {
                //检查是否需要是关注用户才能发帖
                IBarSettingsManager barSettingsManager = DIContainer.Resolve <IBarSettingsManager>();
                BarSettings         barSetting         = barSettingsManager.Get();
                if (barSetting.OnlyFollowerCreatePost)
                {
                    if (currentUser == null)
                    {
                        errorMessage = "您需要先登录并关注此帖吧,才能回帖";
                        return(false);
                    }
                    SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());
                    bool             isSubscribed     = subscribeService.IsSubscribed(sectionId, currentUser.UserId);
                    if (!isSubscribed)
                    {
                        errorMessage = "您需要先关注此帖吧,才能回帖";
                    }
                    return(isSubscribed);
                }
            }
            else
            {
                if (authorizer.BarSection_Manage(barSection))
                {
                    return(true);
                }
                bool isTenantMember = authorizer.AuthorizationService.IsTenantMember(currentUser, barSection.TenantTypeId, barSection.SectionId);
                if (!isTenantMember)
                {
                    errorMessage = "您需要先加入,才能回帖";
                }
                return(isTenantMember);
            }

            //站点设置是否启用了匿名发帖
            ISiteSettingsManager siteSettingsManager = DIContainer.Resolve <ISiteSettingsManager>();
            SiteSettings         siteSettings        = siteSettingsManager.Get();

            if (siteSettings.EnableAnonymousPosting)
            {
                return(true);
            }

            if (currentUser == null)
            {
                errorMessage = "您必须先登录,才能回帖";
                return(false);
            }
            return(true);
        }
コード例 #33
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、@用户(看到了)
        }
コード例 #34
0
ファイル: Authorizer.cs プロジェクト: yaotyl/spb4mono
        /// <summary>
        /// 是否具有创建BarThread的权限
        /// </summary>
        /// <param name="authorizer"></param>
        /// <param name="sectionId">所属帖吧Id</param>
        /// <param name="errorMessage">无权信息提示</param>
        /// <returns></returns>
        public static bool BarThread_Create(this Authorizer authorizer, long sectionId, out string errorMessage)
        {
            errorMessage = string.Empty;
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                errorMessage = "您需要先登录,才能发帖";
                return(false);
            }
            BarSectionService barSectionService = new BarSectionService();
            var barSection = barSectionService.Get(sectionId);

            if (barSection == null)
            {
                errorMessage = "贴吧不存在";
                return(false);
            }

            if (authorizer.BarSection_Manage(barSection))
            {
                return(true);
            }

            if (!authorizer.AuthorizationService.Check(currentUser, PermissionItemKeys.Instance().Bar_CreateThread()))
            {
                if (currentUser.IsModerated)
                {
                    errorMessage = Resources.Resource.Description_ModeratedUser_CreateBarThreadDenied;
                }
                return(false);
            }
            if (barSection.TenantTypeId == TenantTypeIds.Instance().Bar())
            {
                IBarSettingsManager barSettingsManager = DIContainer.Resolve <IBarSettingsManager>();
                BarSettings         barSetting         = barSettingsManager.Get();
                if (barSetting.OnlyFollowerCreateThread)
                {
                    SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());
                    if (subscribeService.IsSubscribed(sectionId, currentUser.UserId))
                    {
                        return(true);
                    }
                    else
                    {
                        errorMessage = "您需要先关注此帖吧,才能发帖";
                        return(false);
                    }
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                if (authorizer.AuthorizationService.IsTenantMember(currentUser, barSection.TenantTypeId, barSection.SectionId))
                {
                    return(true);
                }
                else
                {
                    TenantType tenantType = new TenantTypeService().Get(barSection.TenantTypeId);
                    errorMessage = string.Format("只有加入{0}才能发帖", tenantType.Name);
                    return(false);
                }
            }
        }
コード例 #35
0
ファイル: Authorizer.cs プロジェクト: yaotyl/spb4mono
        /// <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);
        }
コード例 #36
0
ファイル: BarSectionEditModel.cs プロジェクト: hbulzy/SYS
        /// <summary>
        /// 将ViewModel转换成数据库存储实体
        /// </summary>
        /// <returns></returns>
        public BarSection AsBarSection()
        {
            BarSectionService barSectionService = new BarSectionService();

            BarSection barSection = null;
            if (this.SectionId > 0)
                barSection = barSectionService.Get(this.SectionId);
            else
            {
                barSection = BarSection.New();
                barSection.TenantTypeId = TenantTypeIds.Instance().Bar();
            }
            barSection.Name = this.Name;
            barSection.Description = this.Description;
            barSection.IsEnabled = this.IsEnabled;
            barSection.ThreadCategoryStatus = this.ThreadCategoryStatus;
            return barSection;
        }