Ejemplo n.º 1
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
            }) /* 跳向无权访问页 */);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 是否具有设置吧管理员的权限
        /// </summary>
        /// <param name="authorizer"></param>
        /// <param name="barSection"></param>
        /// <returns></returns>
        public static bool BarSection_SetManager(this Authorizer authorizer, BarSection barSection)
        {
            if (barSection == null)
            {
                return(false);
            }

            IUser currentUser = UserContext.CurrentUser;

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

            //吧主
            if (barSection.UserId == currentUser.UserId)
            {
                return(true);
            }



            if (authorizer.IsAdministrator(BarConfig.Instance().ApplicationId))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 创建回复贴
        /// </summary>
        /// <param name="post">回复贴</param>
        public bool Create(BarPost post)
        {
            BarSectionService barSectionService = new BarSectionService();
            BarSection        barSection        = barSectionService.Get(post.SectionId);

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

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

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

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

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

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

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

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

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

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

                EventBus <BarPost, AuditEventArgs> .Instance().OnAfter(post, new AuditEventArgs(null, post.AuditStatus));
            }
            return(id > 0);
        }
Ejemplo n.º 5
0
        //1、版主应该改成管理员,需求、原型图、本方法命名都应该修改;
        //2、帖吧管理员与帖吧的关注者是什么关系,帖吧管理员允许取消对帖吧的关注吗?

        /// <summary>
        /// 是否为吧主
        /// </summary>
        /// <param name="userId">被验证用户Id</param>
        /// <param name="sectionId">帖吧Id</param>
        /// <returns></returns>
        public bool IsSectionOwner(long userId, long sectionId)
        {
            BarSection barSection = Get(sectionId);

            if (barSection == null)
            {
                return(false);
            }
            return(barSection.UserId == userId);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 更新帖吧
        /// </summary>
        /// <param name="section">帖吧</param>
        /// <param name="userId">当前操作人</param>
        /// <param name="managerIds">管理员用户Id</param>
        /// <param name="sectionedFile">帖吧标识图</param>
        public void Update(BarSection section, long userId, IEnumerable <long> managerIds, Stream sectionedFile)
        {
            EventBus <BarSection> .Instance().OnBefore(section, new CommonEventArgs(EventOperationType.Instance().Update()));



            //上传Logo
            if (sectionedFile != null)
            {
                LogoService logoService = new LogoService(TenantTypeIds.Instance().BarSection());
                section.LogoImage = logoService.UploadLogo(section.SectionId, sectionedFile);
            }

            auditService.ChangeAuditStatusForUpdate(userId, section);
            barSectionRepository.Update(section);

            if (managerIds != null && managerIds.Count() > 0)
            {
                List <long> mangagerIds_list = managerIds.ToList();
                mangagerIds_list.Remove(section.UserId);
                managerIds = mangagerIds_list;
            }
            barSectionRepository.UpdateManagerIds(section.SectionId, managerIds);

            if (section.TenantTypeId == TenantTypeIds.Instance().Bar())
            {
                SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());

                //帖吧主、吧管理员自动关注本帖吧
                int  followedCount = 0;
                bool result        = subscribeService.Subscribe(section.SectionId, section.UserId);
                if (result)
                {
                    followedCount++;
                }
                if (managerIds != null && managerIds.Count() > 0)
                {
                    foreach (var managerId in managerIds)
                    {
                        result = subscribeService.Subscribe(section.SectionId, managerId);
                        if (result)
                        {
                            followedCount++;
                        }
                    }
                }

                //增加帖吧的被关注数
                CountService countService = new CountService(TenantTypeIds.Instance().BarSection());
                countService.ChangeCount(CountTypes.Instance().FollowedCount(), section.SectionId, section.UserId, followedCount, true);
            }
            EventBus <BarSection> .Instance().OnAfter(section, new CommonEventArgs(EventOperationType.Instance().Update()));
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 将数据库中的信息转换成EditModel实体
 /// </summary>
 /// <param name="barSection"></param>
 /// <returns></returns>
 public static BarSectionEditModel AsEditModel(this BarSection barSection)
 {
     return(new BarSectionEditModel
     {
         Name = barSection.Name,
         Description = barSection.Description,
         ThreadCategoryStatus = barSection.ThreadCategoryStatus,
         IsEnabled = barSection.IsEnabled,
         SectionId = barSection.SectionId,
         LogoImage = barSection.LogoImage,
         DisplayOrder = barSection.DisplayOrder
     });
 }
Ejemplo n.º 8
0
        /// <summary>
        /// 新建实体时使用
        /// </summary>
        //todo:需要检查成员初始化的类型是否正确
        public static BarSection New()
        {
            BarSection barSection = new BarSection()
            {
                Name         = string.Empty,
                LogoImage    = string.Empty,
                DateCreated  = DateTime.UtcNow,
                Description  = string.Empty,
                DisplayOrder = 100
            };

            return(barSection);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 删除Logo
        /// </summary>
        /// <param name="sectionId">帖吧Id</param>
        public void DeleteLogo(long sectionId)
        {
            LogoService logoService = new LogoService(TenantTypeIds.Instance().BarSection());

            logoService.DeleteLogo(sectionId);
            BarSection section = barSectionRepository.Get(sectionId);

            if (section == null)
            {
                return;
            }
            section.LogoImage = string.Empty;
            barSectionRepository.Update(section);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 删除帖吧
        /// </summary>
        /// <param name="sectionId">帖吧Id</param>
        public void Delete(long sectionId)
        {
            BarSection section = barSectionRepository.Get(sectionId);

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

            //帖子
            BarThreadService barThreadService = new BarThreadService();

            barThreadService.DeletesBySectionId(sectionId);

            CategoryService categoryService = new CategoryService();

            //帖吧分类
            categoryService.ClearCategoriesFromItem(sectionId, null, TenantTypeIds.Instance().BarSection());

            //帖子分类
            var categories = categoryService.GetRootCategories(TenantTypeIds.Instance().BarThread(), sectionId);

            foreach (var category in categories)
            {
                categoryService.Delete(category.CategoryId);
            }
            //帖吧标签
            TagService tagService = new TagService(TenantTypeIds.Instance().BarThread());

            tagService.ClearTagsFromOwner(sectionId);

            //删除Logo
            DeleteLogo(sectionId);

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

            recommendService.Delete(sectionId, TenantTypeIds.Instance().BarSection());

            int affectCount = barSectionRepository.Delete(section);

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

                EventBus <BarSection, AuditEventArgs> .Instance().OnAfter(section, new AuditEventArgs(null, section.AuditStatus));
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 创建主题帖
        /// </summary>
        /// <param name="thread">主题帖</param>
        public bool Create(BarThread thread)
        {
            BarSectionService barSectionService = new BarSectionService();

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

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

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

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

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

                EventBus <BarThread, AuditEventArgs> .Instance().OnAfter(thread, new AuditEventArgs(null, thread.AuditStatus));
            }
            return(id > 0);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 贴吧显示
        /// </summary>
        /// <param name="authorizer"></param>
        /// <param name="barSection"></param>
        /// <returns></returns>
        public static bool BarSection_View(this Authorizer authorizer, BarSection barSection)
        {
            if (barSection == null)
            {
                return(false);
            }

            if (barSection.AuditStatus == AuditStatus.Success)
            {
                return(true);
            }

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

            return(false);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 是否具有管理BarSection的权限
        /// </summary>
        /// <param name="barSection"></param>
        /// <returns></returns>
        public static bool BarSection_Manage(this Authorizer authorizer, BarSection barSection)
        {
            IUser currentUser = UserContext.CurrentUser;

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

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

            if (barSection.AuditStatus == AuditStatus.Success)
            {
                //吧主
                if (barSection.UserId == currentUser.UserId)
                {
                    return(true);
                }

                //吧管理员
                if (authorizer.AuthorizationService.IsTenantManager(currentUser, barSection.TenantTypeId, barSection.SectionId))
                {
                    return(true);
                }
            }

            TenantType tenantType    = new TenantTypeService().Get(barSection.TenantTypeId);
            int        applicationId = BarConfig.Instance().ApplicationId;

            if (tenantType != null)
            {
                applicationId = tenantType.ApplicationId;
            }
            if (authorizer.IsAdministrator(applicationId))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 更新帖吧的审核状态
        /// </summary>
        /// <param name="sectionId">帖吧Id</param>
        /// <param name="isApproved">是否通过审核</param>
        public void UpdateAuditStatus(long sectionId, bool isApproved)
        {
            BarSection  section     = barSectionRepository.Get(sectionId);
            AuditStatus auditStatus = isApproved ? AuditStatus.Success : AuditStatus.Fail;

            if (section.AuditStatus == auditStatus)
            {
                return;
            }
            AuditStatus oldAuditStatus = section.AuditStatus;

            section.AuditStatus = auditStatus;
            barSectionRepository.Update(section);
            string operationType = isApproved ? EventOperationType.Instance().Approved() : EventOperationType.Instance().Disapproved();

            EventBus <BarSection> .Instance().OnAfter(section, new CommonEventArgs(operationType));

            EventBus <BarSection, AuditEventArgs> .Instance().OnAfter(section, new AuditEventArgs(oldAuditStatus, section.AuditStatus));
        }
Ejemplo n.º 15
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);
        }
        /// <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);
            }
        }
Ejemplo n.º 17
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));
            }
        }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 创建帖吧
        /// </summary>
        /// <param name="section">帖吧</param>
        /// <param name="userId">当前操作人</param>
        /// <param name="managerIds">管理员用户Id</param>
        /// <param name="logoFile">帖吧标识图</param>
        /// <returns>是否创建成功</returns>
        public bool Create(BarSection section, long userId, IEnumerable <long> managerIds, Stream logoFile)
        {
            EventBus <BarSection> .Instance().OnBefore(section, new CommonEventArgs(EventOperationType.Instance().Create()));

            //设置审核状态
            auditService.ChangeAuditStatusForCreate(userId, section);

            if (!(section.SectionId > 0))
            {
                section.SectionId = IdGenerator.Next();
            }

            long id = 0;

            long.TryParse(barSectionRepository.Insert(section).ToString(), out id);

            if (id > 0)
            {
                if (managerIds != null && managerIds.Count() > 0)
                {
                    List <long> mangagerIds_list = managerIds.ToList();
                    mangagerIds_list.Remove(section.UserId);
                    managerIds = mangagerIds_list;
                    barSectionRepository.UpdateManagerIds(id, managerIds);
                }
                if (section.TenantTypeId == TenantTypeIds.Instance().Bar())
                {
                    //帖吧主、吧管理员自动关注本帖吧
                    SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());
                    int  followedCount = 0;
                    bool result        = subscribeService.Subscribe(section.SectionId, section.UserId);
                    if (result)
                    {
                        followedCount++;
                    }
                    if (managerIds != null && managerIds.Count() > 0)
                    {
                        foreach (var managerId in managerIds)
                        {
                            result = subscribeService.Subscribe(section.SectionId, managerId);
                            if (result)
                            {
                                followedCount++;
                            }
                        }
                    }
                    //增加帖吧的被关注数
                    CountService countService = new CountService(TenantTypeIds.Instance().BarSection());
                    countService.ChangeCount(CountTypes.Instance().FollowedCount(), section.SectionId, section.UserId, followedCount, true);
                }



                //上传Logo
                if (logoFile != null)
                {
                    LogoService logoService = new LogoService(TenantTypeIds.Instance().BarSection());
                    section.LogoImage = logoService.UploadLogo(section.SectionId, logoFile);
                    barSectionRepository.Update(section);
                }
                EventBus <BarSection> .Instance().OnAfter(section, new CommonEventArgs(EventOperationType.Instance().Create()));

                EventBus <BarSection, AuditEventArgs> .Instance().OnAfter(section, new AuditEventArgs(section.AuditStatus, null));
            }
            return(id > 0);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 是否具有设置吧管理员的权限
        /// </summary>
        /// <param name="authorizer"></param>
        /// <param name="barSection"></param>
        /// <returns></returns>
        public static bool BarSection_SetManager(this Authorizer authorizer, BarSection barSection)
        {
            if (barSection == null)
                return false;

            IUser currentUser = UserContext.CurrentUser;
            if (currentUser == null)
                return false;

            //吧主
            if (barSection.UserId == currentUser.UserId)
                return true;

            if (authorizer.IsAdministrator(BarConfig.Instance().ApplicationId))
                return true;

            return false;
        }
Ejemplo n.º 21
0
        /// <summary>
        /// 贴吧显示
        /// </summary>
        /// <param name="authorizer"></param>
        /// <param name="barSection"></param>
        /// <returns></returns>
        public static bool BarSection_View(this Authorizer authorizer, BarSection barSection)
        {
            if (barSection == null)
                return false;

            if (barSection.AuditStatus == AuditStatus.Success)
                return true;

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

            return false;
        }
Ejemplo n.º 22
0
        /// <summary>
        /// 是否具有管理BarSection的权限
        /// </summary>
        /// <param name="barSection"></param>
        /// <returns></returns>
        public static bool BarSection_Manage(this Authorizer authorizer, BarSection barSection)
        {
            IUser currentUser = UserContext.CurrentUser;
            if (currentUser == null)
                return false;

            if (barSection == null)
                return false;

            if (barSection.AuditStatus == AuditStatus.Success)
            {
                //吧主
                if (barSection.UserId == currentUser.UserId)
                    return true;

                //吧管理员
                if (authorizer.AuthorizationService.IsTenantManager(currentUser, barSection.TenantTypeId, barSection.SectionId))
                    return true;
            }

            TenantType tenantType = new TenantTypeService().Get(barSection.TenantTypeId);
            int applicationId = BarConfig.Instance().ApplicationId;
            if (tenantType != null)
                applicationId = tenantType.ApplicationId;
            if (authorizer.IsAdministrator(applicationId))
                return true;

            return false;
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 新建实体时使用
        /// </summary>
        //todo:需要检查成员初始化的类型是否正确
        public static BarSection New()
        {
            BarSection barSection = new BarSection()
            {
                Name = string.Empty,
                LogoImage = string.Empty,
                DateCreated = DateTime.UtcNow,
                Description = string.Empty,
                DisplayOrder = 100

            };
            return barSection;
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 创建帖吧
        /// </summary>
        /// <param name="section">帖吧</param>
        /// <param name="userId">当前操作人</param>
        /// <param name="managerIds">管理员用户Id</param>
        /// <param name="logoFile">帖吧标识图</param>
        /// <returns>是否创建成功</returns>
        public bool Create(BarSection section, long userId, IEnumerable<long> managerIds, Stream logoFile)
        {
            EventBus<BarSection>.Instance().OnBefore(section, new CommonEventArgs(EventOperationType.Instance().Create()));
            //设置审核状态
            auditService.ChangeAuditStatusForCreate(userId, section);

            if (!(section.SectionId > 0))
                section.SectionId = IdGenerator.Next();

            long id = 0;
            long.TryParse(barSectionRepository.Insert(section).ToString(), out id);

            if (id > 0)
            {
                if (managerIds != null && managerIds.Count() > 0)
                {
                    List<long> mangagerIds_list = managerIds.ToList();
                    mangagerIds_list.Remove(section.UserId);
                    managerIds = mangagerIds_list;
                    barSectionRepository.UpdateManagerIds(id, managerIds);
                }
                if (section.TenantTypeId == TenantTypeIds.Instance().Bar())
                {
                    //帖吧主、吧管理员自动关注本帖吧
                    SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());
                    int followedCount = 0;
                    bool result = subscribeService.Subscribe(section.SectionId, section.UserId);
                    if (result)
                        followedCount++;
                    if (managerIds != null && managerIds.Count() > 0)
                        foreach (var managerId in managerIds)
                        {
                            result = subscribeService.Subscribe(section.SectionId, managerId);
                            if (result)
                                followedCount++;
                        }
                    //增加帖吧的被关注数
                    CountService countService = new CountService(TenantTypeIds.Instance().BarSection());
                    countService.ChangeCount(CountTypes.Instance().FollowedCount(), section.SectionId, section.UserId, followedCount, true);
                }

                //上传Logo
                if (logoFile != null)
                {
                    LogoService logoService = new LogoService(TenantTypeIds.Instance().BarSection());
                    section.LogoImage = logoService.UploadLogo(section.SectionId, logoFile);
                    barSectionRepository.Update(section);
                }
                EventBus<BarSection>.Instance().OnAfter(section, new CommonEventArgs(EventOperationType.Instance().Create()));
                EventBus<BarSection, AuditEventArgs>.Instance().OnAfter(section, new AuditEventArgs(section.AuditStatus, null));
            }
            return id > 0;
        }
Ejemplo n.º 25
0
        /// <summary>
        /// 更新帖吧
        /// </summary>
        /// <param name="section">帖吧</param>
        /// <param name="userId">当前操作人</param>
        /// <param name="managerIds">管理员用户Id</param>
        /// <param name="sectionedFile">帖吧标识图</param>
        public void Update(BarSection section, long userId, IEnumerable<long> managerIds, Stream sectionedFile)
        {
            EventBus<BarSection>.Instance().OnBefore(section, new CommonEventArgs(EventOperationType.Instance().Update()));

            //上传Logo
            if (sectionedFile != null)
            {
                LogoService logoService = new LogoService(TenantTypeIds.Instance().BarSection());
                section.LogoImage = logoService.UploadLogo(section.SectionId, sectionedFile);

            }

            auditService.ChangeAuditStatusForUpdate(userId, section);
            barSectionRepository.Update(section);

            if (managerIds != null && managerIds.Count() > 0)
            {
                List<long> mangagerIds_list = managerIds.ToList();
                mangagerIds_list.Remove(section.UserId);
                managerIds = mangagerIds_list;
            }
            barSectionRepository.UpdateManagerIds(section.SectionId, managerIds);

            if (section.TenantTypeId == TenantTypeIds.Instance().Bar())
            {
                SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());

                //帖吧主、吧管理员自动关注本帖吧
                int followedCount = 0;
                bool result = subscribeService.Subscribe(section.SectionId, section.UserId);
                if (result)
                    followedCount++;
                if (managerIds != null && managerIds.Count() > 0)
                {
                    foreach (var managerId in managerIds)
                    {
                        result = subscribeService.Subscribe(section.SectionId, managerId);
                        if (result)
                            followedCount++;
                    }
                }

                //增加帖吧的被关注数
                CountService countService = new CountService(TenantTypeIds.Instance().BarSection());
                countService.ChangeCount(CountTypes.Instance().FollowedCount(), section.SectionId, section.UserId, followedCount, true);
            }
            EventBus<BarSection>.Instance().OnAfter(section, new CommonEventArgs(EventOperationType.Instance().Update()));
        }
Ejemplo n.º 26
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、@用户(看到了)
        }