void SetStatusInvitationnForJoinTopicEventModule_After(Invitation sender, CommonEventArgs eventArgs)
 {
     if (eventArgs.EventOperationType == EventOperationType.Instance().Update())
     {
         InvitationService invitationService = DIContainer.Resolve<InvitationService>();
         Invitation invitation = invitationService.Get(sender.Id);
         if (invitation != null && invitation.InvitationTypeKey == InvitationTypeKeys.Instance().InviteJoinTopic() && invitation.Status == InvitationStatus.Accept)
         {
             TopicService groupService = new TopicService();
             TopicMember member=TopicMember.New();
             member.TopicId=sender.RelativeObjectId;
             member.UserId = sender.UserId;
             member.IsManager = false;
             groupService.CreateTopicMember(member);
         }
         else if (invitation != null && invitation.InvitationTypeKey == InvitationTypeKeys.Instance().ApplyJoinTopic() && invitation.Status == InvitationStatus.Accept)
         {
             TopicService groupService = new TopicService();
             TopicMember member = TopicMember.New();
             member.TopicId = sender.RelativeObjectId;
             member.UserId = sender.SenderUserId;
             member.IsManager = false;
             groupService.CreateTopicMember(member);
             IEnumerable<long> a = groupService.GetTopicMemberApplies(sender.RelativeObjectId, TopicMemberApplyStatus.Pending, 20, 1).Where(n => n.UserId == sender.SenderUserId).Select(m => m.Id);
             groupService.ApproveTopicMemberApply(a,true);
         }
         else if (invitation != null && invitation.InvitationTypeKey == InvitationTypeKeys.Instance().ApplyJoinTopic() && invitation.Status == InvitationStatus.Refuse)
         {
             TopicService groupService = new TopicService();
             IEnumerable<long> a = groupService.GetTopicMemberApplies(sender.RelativeObjectId, TopicMemberApplyStatus.Pending, 20, 1).Where(n => n.UserId == sender.SenderUserId).Select(m => m.Id);
             groupService.ApproveTopicMemberApply(a,false);
         }
     }
 }
 /// <summary>
 /// 详细页面地址
 /// </summary>
 /// <param name="itemId">推荐内容Id</param>
 /// <returns></returns>
 public string RecommendItemDetail(long itemId)
 {
     TopicEntity group = new TopicService().Get(itemId);
     if (group == null)
         return string.Empty;
     string userName = UserIdToUserNameDictionary.GetUserName(group.UserId);
     return SiteUrls.Instance().TopicHome(itemId);
 }
 /// <summary>
 /// 获取接收人UserId集合
 /// </summary>
 /// <param name="activityService">动态业务逻辑类</param>
 /// <param name="activity">动态</param>
 /// <returns></returns>
 IEnumerable<long> IActivityReceiverGetter.GetReceiverUserIds(ActivityService activityService, Activity activity)
 {
     TopicService groupService = new TopicService();
     IEnumerable<long> userIds = groupService.GetUserIdsOfTopic(activity.OwnerId);
     bool isPublic = false;
     var group = groupService.Get(activity.OwnerId);
     if (group != null)
         isPublic = group.IsPublic;
     if (userIds == null)
         return new List<long>();
     return userIds.Where(n => IsReceiveActivity(activityService, isPublic, n, activity));
 }
        /// <summary>
        /// 动态处理程序
        /// </summary>
        /// <param name="groupMember"></param>
        /// <param name="eventArgs"></param>
        private void TopicMemberActivityModule_After(TopicMember groupMember, CommonEventArgs eventArgs)
        {
            ActivityService activityService = new ActivityService();
            if (eventArgs.EventOperationType == EventOperationType.Instance().Create())
            {
                //生成动态
                if (groupMember == null)
                    return;
                var group = new TopicService().Get(groupMember.TopicId);
                if (group == null)
                    return;
                //生成Owner为专题的动态
                Activity actvityOfTopic = Activity.New();
                actvityOfTopic.ActivityItemKey = ActivityItemKeys.Instance().CreateTopicMember();
                actvityOfTopic.ApplicationId = TopicConfig.Instance().ApplicationId;
                actvityOfTopic.IsOriginalThread = true;
                actvityOfTopic.IsPrivate = !group.IsPublic;
                actvityOfTopic.UserId = groupMember.UserId;
                actvityOfTopic.ReferenceId = 0;
                actvityOfTopic.ReferenceTenantTypeId = string.Empty;
                actvityOfTopic.SourceId = groupMember.Id;
                actvityOfTopic.TenantTypeId = TenantTypeIds.Instance().User();
                actvityOfTopic.OwnerId = group.TopicId;
                actvityOfTopic.OwnerName = group.TopicName;
                actvityOfTopic.OwnerType = ActivityOwnerTypes.Instance().Topic();

                activityService.Generate(actvityOfTopic, false);

                //生成Owner为用户的动态
                Activity actvityOfUser = Activity.New();
                actvityOfUser.ActivityItemKey = ActivityItemKeys.Instance().JoinTopic();
                actvityOfUser.ApplicationId = actvityOfTopic.ApplicationId;
                actvityOfUser.HasImage = actvityOfTopic.HasImage;
                actvityOfUser.HasMusic = actvityOfTopic.HasMusic;
                actvityOfUser.HasVideo = actvityOfTopic.HasVideo;
                actvityOfUser.IsOriginalThread = actvityOfTopic.IsOriginalThread;
                actvityOfUser.IsPrivate = actvityOfTopic.IsPrivate;
                actvityOfUser.UserId = actvityOfTopic.UserId;
                actvityOfUser.ReferenceId = actvityOfTopic.ReferenceId;
                actvityOfTopic.ReferenceTenantTypeId = actvityOfTopic.ReferenceTenantTypeId;
                actvityOfUser.SourceId = actvityOfTopic.SourceId;

                actvityOfUser.TenantTypeId = actvityOfTopic.TenantTypeId;
                actvityOfUser.OwnerId = groupMember.UserId;
                actvityOfUser.OwnerName = groupMember.User.DisplayName;
                actvityOfUser.OwnerType = ActivityOwnerTypes.Instance().User();
                activityService.Generate(actvityOfUser, false);
            }
            else if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) //删除动态
            {
                activityService.DeleteSource(TenantTypeIds.Instance().User(), groupMember.UserId);
            }
        }
        ThemeAppearance IThemeResolver.GetRequestTheme(RequestContext controllerContext)
        {
            string      spaceKey = controllerContext.GetParameterFromRouteDataOrQueryString("SpaceKey");
            TopicEntity topic    = new TopicService().Get(spaceKey);

            if (topic == null)
            {
                throw new ExceptionFacade("找不到专题");
            }

            string      themeKey      = null;
            string      appearanceKey = null;
            PresentArea pa            = new PresentAreaService().Get(PresentAreaKeysOfExtension.TopicSpace);

            if (pa == null)
            {
                throw new ExceptionFacade("找不到专题呈现区域");
            }

            if (pa.EnableThemes)
            {
                if (topic.IsUseCustomStyle)
                {
                    themeKey      = "Default";
                    appearanceKey = "Default";
                }
                else
                {
                    string[] themeAppearanceArray = topic.ThemeAppearance.Split(',');
                    var      appearance           = new ThemeService().GetThemeAppearance(PresentAreaKeysOfExtension.TopicSpace, topic.ThemeAppearance);

                    if (appearance != null && themeAppearanceArray.Count() == 2)
                    {
                        themeKey      = themeAppearanceArray[0];
                        appearanceKey = themeAppearanceArray[1];
                    }
                }
            }
            if (themeKey == null || appearanceKey == null)
            {
                themeKey      = pa.DefaultThemeKey;
                appearanceKey = pa.DefaultAppearanceKey;
            }

            return(new ThemeService().GetThemeAppearance(PresentAreaKeysOfExtension.TopicSpace, themeKey, appearanceKey));
        }
        /// <summary>
        /// 获取接收人UserId集合
        /// </summary>
        /// <param name="activityService">动态业务逻辑类</param>
        /// <param name="activity">动态</param>
        /// <returns></returns>
        IEnumerable <long> IActivityReceiverGetter.GetReceiverUserIds(ActivityService activityService, Activity activity)
        {
            TopicService       groupService = new TopicService();
            IEnumerable <long> userIds      = groupService.GetUserIdsOfTopic(activity.OwnerId);
            bool isPublic = false;
            var  group    = groupService.Get(activity.OwnerId);

            if (group != null)
            {
                isPublic = group.IsPublic;
            }
            if (userIds == null)
            {
                return(new List <long>());
            }
            return(userIds.Where(n => IsReceiveActivity(activityService, isPublic, n, activity)));
        }
        ThemeAppearance IThemeResolver.GetRequestTheme(RequestContext controllerContext)
        {
            string spaceKey = controllerContext.GetParameterFromRouteDataOrQueryString("SpaceKey");
            TopicEntity topic = new TopicService().Get(spaceKey);
            if (topic == null)
                throw new ExceptionFacade("找不到专题");

            string themeKey = null;
            string appearanceKey = null;
            PresentArea pa = new PresentAreaService().Get(PresentAreaKeysOfExtension.TopicSpace);
            if (pa == null)
                throw new ExceptionFacade("找不到专题呈现区域");

            if (pa.EnableThemes)
            {
                if (topic.IsUseCustomStyle)
                {
                    themeKey = "Default";
                    appearanceKey = "Default";
                }
                else
                {
                    string[] themeAppearanceArray = topic.ThemeAppearance.Split(',');
                    var appearance = new ThemeService().GetThemeAppearance(PresentAreaKeysOfExtension.TopicSpace, topic.ThemeAppearance);

                    if (appearance != null && themeAppearanceArray.Count() == 2)
                    {
                        themeKey = themeAppearanceArray[0];
                        appearanceKey = themeAppearanceArray[1];
                    }
                }
            }
            if (themeKey == null || appearanceKey == null)
            {
                themeKey = pa.DefaultThemeKey;
                appearanceKey = pa.DefaultAppearanceKey;
            }

            return new ThemeService().GetThemeAppearance(PresentAreaKeysOfExtension.TopicSpace, themeKey, appearanceKey);
        }
Esempio n. 8
0
        /// <summary>
        /// 是否具有管理Topic的权限
        /// </summary>
        /// <param name="Topic"></param>
        /// <returns></returns>
        public static bool Topic_Manage(this Authorizer authorizer, TopicEntity group)
        {
            if (group == null)
            {
                return(false);
            }

            IUser currentUser = UserContext.CurrentUser;

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

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

            if (currentUser.IsContentAdministrator())
            {
                return(true);
            }

            //群主
            if (group.UserId == currentUser.UserId)
            {
                return(true);
            }

            TopicService groupService = new TopicService();

            //群管理员
            if (groupService.IsManager(group.TopicId, currentUser.UserId))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 9
0
        /// <summary>
        /// 转换成groupEntity类型
        /// </summary>
        /// <returns></returns>
        public TopicEntity AsTopicEntity()
        {
            CategoryService categoryService = new CategoryService();
            TopicEntity     topicEntity     = null;

            //创建专题
            if (this.TopicId == 0)
            {
                topicEntity             = TopicEntity.New();
                topicEntity.UserId      = UserContext.CurrentUser.UserId;
                topicEntity.DateCreated = DateTime.UtcNow;
                topicEntity.TopicKey    = this.TopicKey;
            }
            //编辑专题
            else
            {
                TopicService topicService = new TopicService();
                topicEntity = topicService.Get(this.TopicId);
            }
            topicEntity.IsPublic  = this.IsPublic;
            topicEntity.TopicName = this.TopicName;
            if (Logo != null)
            {
                topicEntity.Logo = this.Logo;
            }
            topicEntity.Description        = Formatter.FormatMultiLinePlainTextForStorage(this.Description == null ? string.Empty : this.Description, true);
            topicEntity.AreaCode           = this.AreaCode ?? string.Empty;
            topicEntity.JoinWay            = this.JoinWay;
            topicEntity.EnableMemberInvite = this.EnableMemberInvite;
            //topickey 去掉空格,变为小写字母
            topicEntity.TopicKey = this.TopicKey.ToLower().Replace(" ", "-");

            if (JoinWay == TopicJoinWay.ByQuestion)
            {
                topicEntity.Question = this.Question;
                topicEntity.Answer   = this.Answer;
            }
            return(topicEntity);
        }
Esempio n. 10
0
        /// <summary>
        /// 是否具有浏览专题的权限
        /// </summary>
        /// <param name="topic"></param>
        /// <returns></returns>
        public static bool Topic_View(this Authorizer authorizer, TopicEntity topic)
        {
            if (topic == null)
            {
                return(false);
            }

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

                if (UserContext.CurrentUser == null)
                {
                    return(false);
                }

                if (authorizer.Topic_Manage(topic))
                {
                    return(true);
                }

                TopicService groupService = new TopicService();
                if (groupService.IsMember(topic.TopicId, UserContext.CurrentUser.UserId))
                {
                    return(true);
                }
            }

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

            return(false);
        }
Esempio n. 11
0
        /// <summary>
        /// 是否具有邀请好友加入专题的权限
        /// </summary>
        /// <param name="group"></param>
        /// <returns></returns>
        public static bool Topic_Invite(this Authorizer authorizer, TopicEntity group)
        {
            if (group == null)
            {
                return(false);
            }
            if (UserContext.CurrentUser == null)
            {
                return(false);
            }

            TopicService groupService = new TopicService();

            if (authorizer.Topic_Manage(group))
            {
                return(true);
            }
            if (group.EnableMemberInvite && groupService.IsMember(group.TopicId, UserContext.CurrentUser.UserId))
            {
                return(true);
            }

            return(false);
        }
 /// <summary>
 /// 删除用户在应用中的数据
 /// </summary>
 /// <param name="userId">用户Id</param>
 /// <param name="takeOverUserName">用于接管删除用户时不能删除的内容(例如:用户创建的专题)</param>
 /// <param name="isTakeOver">是否接管被删除用户可被接管的内容</param>
 protected override void DeleteUser(long userId, string takeOverUserName, bool isTakeOver)
 {
     TopicService topicService = new TopicService();
     topicService.DeleteUser(userId, takeOverUserName, isTakeOver);
 }
Esempio n. 13
0
        /// <summary>
        /// 是否具有管理Topic的权限
        /// </summary>
        /// <param name="authorizer"></param>
        /// <param name="groupId"></param>
        /// <returns></returns>
        public static bool Topic_Manage(this Authorizer authorizer, long groupId)
        {
            TopicEntity group = new TopicService().Get(groupId);

            return(Topic_Manage(authorizer, group));
        }
        /// <summary>
        /// 设置/取消管理员通知处理程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        private void SetManagerNoticeEventModule_After(TopicMember sender, CommonEventArgs eventArgs)
        {
            if (eventArgs.EventOperationType != EventOperationType.Instance().SetTopicManager() && eventArgs.EventOperationType != EventOperationType.Instance().CancelTopicManager())
                return;

            TopicService groupService = new TopicService();
            TopicEntity entity = groupService.Get(sender.TopicId);
            if (entity == null)
                return;

            User senderUser = DIContainer.Resolve<IUserService>().GetFullUser(sender.UserId);
            if (senderUser == null)
                return;

            NoticeService noticeService = DIContainer.Resolve<NoticeService>();

            Notice notice = Notice.New();
            notice.UserId = sender.UserId;
            notice.ApplicationId = TopicConfig.Instance().ApplicationId;
            notice.TypeId = NoticeTypeIds.Instance().Hint();
            notice.LeadingActorUserId = 0;
            notice.LeadingActor = string.Empty;
            notice.LeadingActorUrl = string.Empty;
            notice.RelativeObjectId = sender.TopicId;
            notice.RelativeObjectName = StringUtility.Trim(entity.TopicName, 64);
            notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().TopicHome(entity.TopicKey));

            if (eventArgs.EventOperationType == EventOperationType.Instance().SetTopicManager())
            {
                notice.TemplateName = NoticeTemplateNames.Instance().SetTopicManager();
            }
            else
            {
                notice.TemplateName = NoticeTemplateNames.Instance().CannelTopicManager();
            }
            noticeService.Create(notice);
        }
        /// <summary>
        /// 是否具有管理Topic的权限
        /// </summary>
        /// <param name="Topic"></param>
        /// <returns></returns>
        public static bool Topic_Manage(this Authorizer authorizer, TopicEntity group)
        {


            if (group == null)
                return false;

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

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

            if (currentUser.IsContentAdministrator())
                return true;

            //群主
            if (group.UserId == currentUser.UserId)
                return true;

            TopicService groupService = new TopicService();
            //群管理员
            if (groupService.IsManager(group.TopicId, currentUser.UserId))
                return true;

            return false;
        }
Esempio n. 16
0
        /// <summary>
        /// 删除用户在应用中的数据
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="takeOverUserName">用于接管删除用户时不能删除的内容(例如:用户创建的专题)</param>
        /// <param name="isTakeOver">是否接管被删除用户可被接管的内容</param>
        protected override void DeleteUser(long userId, string takeOverUserName, bool isTakeOver)
        {
            TopicService topicService = new TopicService();

            topicService.DeleteUser(userId, takeOverUserName, isTakeOver);
        }
        private void AuthorizeCore(AuthorizationContext filterContext)
        {
            string spaceKey = UserContext.CurrentSpaceKey(filterContext);

            if (string.IsNullOrEmpty(spaceKey))
            {
                throw new ExceptionFacade("spaceKey为null");
            }
            TopicService TopicService = new TopicService();
            TopicEntity  Topic        = TopicService.Get(spaceKey);

            if (Topic == null)
            {
                throw new ExceptionFacade("找不到当前专题");
            }

            IUser currentUser = UserContext.CurrentUser;



            //判断访问专题权限
            if (!DIContainer.Resolve <Authorizer>().Topic_View(Topic))
            {
                if (currentUser == null)
                {
                    filterContext.Result = new RedirectResult(SiteUrls.Instance().Login(true));
                }
                else
                {
                    if (Topic.AuditStatus != AuditStatus.Success)
                    {
                        filterContext.Result = new RedirectResult(SiteUrls.Instance().SystemMessage(filterContext.Controller.TempData, new SystemMessageViewModel
                        {
                            Title             = "无权访问专题!",
                            Body              = "该专题还没有通过审核,所以不能访问!",
                            StatusMessageType = StatusMessageType.Hint
                        }, filterContext.HttpContext.Request.RawUrl) /* 跳向无权访问页 */);
                    }
                    else
                    {
                        filterContext.Result = new RedirectResult(SiteUrls.Instance().SystemMessage(filterContext.Controller.TempData, new SystemMessageViewModel
                        {
                            Title             = "无权访问专题!",
                            Body              = "你没有访问该专题的权限",
                            StatusMessageType = StatusMessageType.Hint
                        }, filterContext.HttpContext.Request.RawUrl) /* 跳向无权访问页 */);
                    }
                }
                return;
            }

            //判断该用户是否有访问该专题管理页面的权限
            if (!RequireManager)
            {
                return;
            }
            //匿名用户要求先登录跳转
            if (currentUser == null)
            {
                filterContext.Result = new RedirectResult(SiteUrls.Instance().Login(true));
                return;
            }

            if (DIContainer.Resolve <Authorizer>().Topic_Manage(Topic))
            {
                return;
            }
            filterContext.Result = new RedirectResult(SiteUrls.Instance().SystemMessage(filterContext.Controller.TempData, new SystemMessageViewModel
            {
                Title             = "无权访问",
                Body              = "您无权访问此页面,只有群主或管理员才能访问",
                StatusMessageType = StatusMessageType.Hint
            }) /* 跳向无权访问页 */);
        }
        /// <summary>
        /// 是否具有浏览专题的权限
        /// </summary>
        /// <param name="topic"></param>
        /// <returns></returns>
        public static bool Topic_View(this Authorizer authorizer, TopicEntity topic)
        {
            if (topic == null)
                return false;

            if (topic.AuditStatus == AuditStatus.Success)
            {
                if (topic.IsPublic)
                    return true;

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

                if (authorizer.Topic_Manage(topic))
                    return true;

                TopicService groupService = new TopicService();
                if (groupService.IsMember(topic.TopicId, UserContext.CurrentUser.UserId))
                    return true;
            }

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

            return false;
        }
        /// <summary>
        /// 更新皮肤
        /// </summary>
        /// <param name="ownerId">拥有者Id(如:用户Id、专题Id)</param>
        /// <param name="isUseCustomStyle">是否使用自定义皮肤</param>
        /// <param name="themeAppearance">themeKey与appearanceKey用逗号关联</param>
        public void ChangeThemeAppearance(long ownerId, bool isUseCustomStyle, string themeAppearance)
        {
            var topicService = new TopicService();
            TopicEntity topic = topicService.Get(ownerId);
            if (topic == null)
                throw new ExceptionFacade("找不到专题");

            new ThemeService().ChangeThemeAppearanceUserCount(PresentAreaKeysOfExtension.TopicSpace, topic.IsUseCustomStyle ? string.Empty : topic.ThemeAppearance, isUseCustomStyle ? string.Empty : themeAppearance);
            new TopicService().ChangeThemeAppearance(ownerId, isUseCustomStyle, themeAppearance);
        }
        /// <summary>
        /// 获取用户当前选中的皮肤
        /// </summary>
        /// <param name="ownerId">拥有者Id(如:用户Id、专题Id)</param>
        /// <returns></returns>
        public string GetThemeAppearance(long ownerId)
        {
            var topicService = new TopicService();
            TopicEntity topic = topicService.Get(ownerId);
            if (topic == null)
                return string.Empty;
            PresentArea pa = new PresentAreaService().Get(PresentAreaKeysOfExtension.TopicSpace);
            if (pa != null && !pa.EnableThemes)
            {
                return pa.DefaultThemeKey + "," + pa.DefaultAppearanceKey;
            }

            if (topic.IsUseCustomStyle)
            {
                return "Default,Default";
            }
            else if (!string.IsNullOrEmpty(topic.ThemeAppearance))
            {
                var appearance = new ThemeService().GetThemeAppearance(PresentAreaKeysOfExtension.TopicSpace, topic.ThemeAppearance);
                if (appearance != null)
                    return topic.ThemeAppearance;
            }

            if (pa != null)
            {
                return pa.DefaultThemeKey + "," + pa.DefaultAppearanceKey;
            }
            return string.Empty;
        }
        void IThemeResolver.IncludeStyle(RequestContext controllerContext)
        {
            string      spaceKey = controllerContext.GetParameterFromRouteDataOrQueryString("SpaceKey");
            TopicEntity topic    = new TopicService().Get(spaceKey);

            if (topic == null)
            {
                return;
            }
            PresentArea presentArea = new PresentAreaService().Get(PresentAreaKeysOfExtension.TopicSpace);

            if (presentArea == null)
            {
                return;
            }


            string themeKey      = null;
            string appearanceKey = null;

            IPageResourceManager resourceManager = DIContainer.ResolvePerHttpRequest <IPageResourceManager>();

            if (!presentArea.EnableThemes)
            {
                string themeCssPath      = string.Format("{0}/{1}/theme.css", presentArea.ThemeLocation, presentArea.DefaultThemeKey);
                string appearanceCssPath = string.Format("{0}/{1}/Appearances/{2}/appearance.css", presentArea.ThemeLocation, presentArea.DefaultThemeKey, presentArea.DefaultAppearanceKey);

                resourceManager.IncludeStyle(themeCssPath);
                resourceManager.IncludeStyle(appearanceCssPath);
                return;
            }

            if (topic.IsUseCustomStyle)
            {
                var customStyleEntity = new CustomStyleService().Get(presentArea.PresentAreaKey, topic.TopicId);
                if (customStyleEntity == null)
                {
                    return;
                }
                CustomStyle customStyle = customStyleEntity.CustomStyle;
                if (customStyle == null)
                {
                    return;
                }
                string themeCssPath      = string.Format("{0}/Custom/theme{1}.css", presentArea.ThemeLocation, customStyle.IsDark ? "-deep" : "");
                string appearanceCssPath = SiteUrls.Instance().CustomStyle(presentArea.PresentAreaKey, topic.TopicId);
                resourceManager.IncludeStyle(themeCssPath);
                resourceManager.IncludeStyle(appearanceCssPath);
                StringBuilder builder = new StringBuilder();
                builder.AppendLine(".tn-page-bg{");
                if (customStyle.IsUseBackgroundImage && !string.IsNullOrEmpty(customStyle.BackgroundImageStyle.Url))
                {
                    builder.AppendLine("background-image:url('" + customStyle.BackgroundImageStyle.Url + @"');");
                    builder.AppendFormat("background-repeat:{0};\n", customStyle.BackgroundImageStyle.IsRepeat ? "repeat" : "no-repeat");
                    builder.AppendFormat("background-attachment:{0};\n", customStyle.BackgroundImageStyle.IsFix ? "fixed" : "scroll");
                    string position = "center";
                    switch (customStyle.BackgroundImageStyle.BackgroundPosition)
                    {
                    case BackgroundPosition.Left:
                        position = "left";
                        break;

                    case BackgroundPosition.Center:
                        position = "center";
                        break;

                    case BackgroundPosition.Right:
                        position = "right";
                        break;

                    default:
                        position = "center";
                        break;
                    }
                    builder.AppendFormat("background-position:{0} top;\n", position);
                }

                builder.AppendLine("}");

                resourceManager.RegisterStyleBlock(builder.ToString());
            }
            else
            {
                string[] themeAppearanceArray = topic.ThemeAppearance.Split(',');
                var      appearance           = new ThemeService().GetThemeAppearance(PresentAreaKeysOfExtension.TopicSpace, topic.ThemeAppearance);

                if (appearance != null && themeAppearanceArray.Count() == 2)
                {
                    themeKey      = themeAppearanceArray[0];
                    appearanceKey = themeAppearanceArray[1];
                }
                else
                {
                    themeKey      = presentArea.DefaultThemeKey;
                    appearanceKey = presentArea.DefaultAppearanceKey;
                }

                string themeCssPath      = string.Format("{0}/{1}/theme.css", presentArea.ThemeLocation, themeKey);
                string appearanceCssPath = string.Format("{0}/{1}/Appearances/{2}/appearance.css", presentArea.ThemeLocation, themeKey, appearanceKey);

                resourceManager.IncludeStyle(themeCssPath);
                resourceManager.IncludeStyle(appearanceCssPath);
            }
        }
 /// <summary>
 /// 是否具有管理Topic的权限
 /// </summary>
 /// <param name="authorizer"></param>
 /// <param name="groupId"></param>
 /// <returns></returns>
 public static bool Topic_Manage(this Authorizer authorizer, long groupId)
 {
     TopicEntity group = new TopicService().Get(groupId);
     return Topic_Manage(authorizer, group);
 }
        /// <summary>
        /// 通知处理程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        private void TopicMemberApplyNoticeModule_After(TopicMemberApply sender, CommonEventArgs eventArgs)
        {
            TopicService groupService = new TopicService();
            TopicEntity entity = groupService.Get(sender.TopicId);
            if (entity == null)
                return;

            User senderUser = DIContainer.Resolve<IUserService>().GetFullUser(sender.UserId);
            if (senderUser == null)
                return;
            InvitationService invitationService = new InvitationService();
            Invitation invitation;
            NoticeService noticeService = DIContainer.Resolve<NoticeService>();
            Notice notice;
            if (eventArgs.EventOperationType == EventOperationType.Instance().Create())
            {
                if (sender.ApplyStatus == TopicMemberApplyStatus.Pending)
                {
                    List<long> toUserIds = new List<long>();
                    toUserIds.Add(entity.UserId);
                    toUserIds.AddRange(entity.TopicManagers.Select(n => n.UserId));
                    foreach (var toUserId in toUserIds)
                    {
                        //申请加入专题的请求
                        if (!groupService.IsMember(sender.TopicId, sender.UserId))
                        {
                            invitation = Invitation.New();
                            invitation.ApplicationId = TopicConfig.Instance().ApplicationId;
                            invitation.InvitationTypeKey = InvitationTypeKeys.Instance().ApplyJoinTopic();
                            invitation.UserId = toUserId;
                            invitation.SenderUserId = sender.UserId;
                            invitation.Sender = senderUser.DisplayName;
                            invitation.SenderUrl = SiteUrls.Instance().SpaceHome(sender.UserId);
                            invitation.RelativeObjectId = sender.TopicId;
                            invitation.RelativeObjectName = entity.TopicName;
                            invitation.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().TopicHome(entity.TopicKey));
                            invitation.Remark = sender.ApplyReason;
                            invitationService.Create(invitation);
                        }
                    }
                }
            }

            string noticeTemplateName = string.Empty;
            if (eventArgs.EventOperationType == EventOperationType.Instance().Approved())
            {
                if (sender.ApplyStatus == TopicMemberApplyStatus.Approved)
                {
                    noticeTemplateName = NoticeTemplateNames.Instance().MemberApplyApproved();
                }
            }
            else if (eventArgs.EventOperationType == EventOperationType.Instance().Disapproved())
            {
                if (sender.ApplyStatus == TopicMemberApplyStatus.Disapproved)
                {
                    noticeTemplateName = NoticeTemplateNames.Instance().MemberApplyDisapproved();
                }
            }

            if (string.IsNullOrEmpty(noticeTemplateName))
                return;

            notice = Notice.New();

            notice.UserId = sender.UserId;
            notice.ApplicationId = TopicConfig.Instance().ApplicationId;
            notice.TypeId = NoticeTypeIds.Instance().Hint();
            //notice.LeadingActorUserId = UserContext.CurrentUser.UserId;
            //notice.LeadingActor = UserContext.CurrentUser.DisplayName;
            //notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(UserContext.CurrentUser.UserId));
            notice.RelativeObjectId = sender.TopicId;
            notice.RelativeObjectName = StringUtility.Trim(entity.TopicName, 64);
            notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().TopicHome(entity.TopicKey));
            notice.TemplateName = noticeTemplateName;
            noticeService.Create(notice);
        }
 /// <summary>
 /// 是否具有删除访客记录的权限
 /// </summary>
 /// <param name="authorizer"></param>
 /// <param name="groupId"></param>
 /// <param name="userId"></param>
 /// <returns></returns>
 public static bool Topic_DeleteVisitor(this Authorizer authorizer, long groupId, long userId)
 {
     bool result = false;
     TopicEntity group = new TopicService().Get(groupId);
     IUser currentUser = UserContext.CurrentUser;
     if (currentUser != null && currentUser.UserId == userId)
     {
         result = true;
     }
     else
     {
         result = Topic_Manage(authorizer, group);
     }
     return result;
 }
        private void AuthorizeCore(AuthorizationContext filterContext)
        {
            string spaceKey = UserContext.CurrentSpaceKey(filterContext);

            if (string.IsNullOrEmpty(spaceKey))
                throw new ExceptionFacade("spaceKey为null");
            TopicService TopicService = new TopicService();
            TopicEntity Topic = TopicService.Get(spaceKey);
            if (Topic == null)
                throw new ExceptionFacade("找不到当前专题");

            IUser currentUser = UserContext.CurrentUser;



            //判断访问专题权限
            if (!DIContainer.Resolve<Authorizer>().Topic_View(Topic))
            {
                if (currentUser == null)
                    filterContext.Result = new RedirectResult(SiteUrls.Instance().Login(true));
                else
                {
                    if (Topic.AuditStatus != AuditStatus.Success)
                    {
                        filterContext.Result = new RedirectResult(SiteUrls.Instance().SystemMessage(filterContext.Controller.TempData, new SystemMessageViewModel
                        {
                            Title = "无权访问专题!",
                            Body = "该专题还没有通过审核,所以不能访问!",
                            StatusMessageType = StatusMessageType.Hint
                        }, filterContext.HttpContext.Request.RawUrl)/* 跳向无权访问页 */);
                    }
                    else
                    {
                        filterContext.Result = new RedirectResult(SiteUrls.Instance().SystemMessage(filterContext.Controller.TempData, new SystemMessageViewModel
                        {
                            Title = "无权访问专题!",
                            Body = "你没有访问该专题的权限",
                            StatusMessageType = StatusMessageType.Hint
                        }, filterContext.HttpContext.Request.RawUrl)/* 跳向无权访问页 */);
                    }
                }
                return;
            }

            //判断该用户是否有访问该专题管理页面的权限
            if (!RequireManager)
                return;
            //匿名用户要求先登录跳转
            if (currentUser == null)
            {
                filterContext.Result = new RedirectResult(SiteUrls.Instance().Login(true));
                return;
            }

            if (DIContainer.Resolve<Authorizer>().Topic_Manage(Topic))
                return;
            filterContext.Result = new RedirectResult(SiteUrls.Instance().SystemMessage(filterContext.Controller.TempData, new SystemMessageViewModel
            {
                Title = "无权访问",
                Body = "您无权访问此页面,只有群主或管理员才能访问",
                StatusMessageType = StatusMessageType.Hint
            })/* 跳向无权访问页 */);
        }
        /// <summary>
        /// 是否具有邀请好友加入专题的权限
        /// </summary>
        /// <param name="group"></param>
        /// <returns></returns>
        public static bool Topic_Invite(this Authorizer authorizer, TopicEntity group)
        {
            if (group == null)
                return false;
            if (UserContext.CurrentUser == null)
                return false;

            TopicService groupService = new TopicService();
            if (authorizer.Topic_Manage(group))
                return true;
            if (group.EnableMemberInvite && groupService.IsMember(group.TopicId, UserContext.CurrentUser.UserId))
                return true;

            return false;
        }
        /// <summary>
        /// 通知处理程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        private void TopicMemberNoticeModule_After(TopicMember sender, CommonEventArgs eventArgs)
        {
            if (eventArgs.EventOperationType != EventOperationType.Instance().Delete() && eventArgs.EventOperationType != EventOperationType.Instance().Create() && sender != null)
                return;
            TopicService groupService = new TopicService();
            TopicEntity entity = groupService.Get(sender.TopicId);
            if (entity == null)
                return;

            User senderUser = DIContainer.Resolve<IUserService>().GetFullUser(sender.UserId);
            if (senderUser == null)
                return;

            NoticeService noticeService = DIContainer.Resolve<NoticeService>();
            Notice notice;

            List<long> toUserIds = new List<long>();
            toUserIds.Add(entity.UserId);
            toUserIds.AddRange(entity.TopicManagers.Select(n => n.UserId));
            //删除专题成员通知群管理员
            if (eventArgs.EventOperationType == EventOperationType.Instance().Delete())
            {
                foreach (var toUserId in toUserIds)
                {
                    if (toUserId == sender.UserId)
                        continue;
                    notice = Notice.New();
                    notice.UserId = toUserId;
                    notice.ApplicationId = TopicConfig.Instance().ApplicationId;
                    notice.TypeId = NoticeTypeIds.Instance().Hint();
                    notice.LeadingActorUserId = sender.UserId;
                    notice.LeadingActor = senderUser.DisplayName;
                    notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId));
                    notice.RelativeObjectId = sender.TopicId;
                    notice.RelativeObjectName = StringUtility.Trim(entity.TopicName, 64);
                    notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().TopicHome(entity.TopicKey));
                    notice.TemplateName = NoticeTemplateNames.Instance().MemberQuit();
                    noticeService.Create(notice);
                }
            }
            else if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) //添加群成员时向群管理员发送通知
            {
                foreach (var toUserId in toUserIds)
                {
                    if (toUserId == sender.UserId)
                        continue;
                    notice = Notice.New();
                    notice.UserId = toUserId;
                    notice.ApplicationId = TopicConfig.Instance().ApplicationId;
                    notice.TypeId = NoticeTypeIds.Instance().Hint();
                    notice.LeadingActorUserId = sender.UserId;
                    notice.LeadingActor = senderUser.DisplayName;
                    notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId));
                    notice.RelativeObjectId = sender.TopicId;
                    notice.RelativeObjectName = StringUtility.Trim(entity.TopicName, 64);
                    notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().TopicHome(entity.TopicKey));
                    notice.TemplateName = NoticeTemplateNames.Instance().MemberJoin();
                    noticeService.Create(notice);
                }
                //向加入者发送通知

                //notice = Notice.New();
                //notice.UserId = sender.UserId;
                //notice.ApplicationId = TopicConfig.Instance().ApplicationId;
                //notice.TypeId = NoticeTypeIds.Instance().Hint();
                //notice.LeadingActorUserId = sender.UserId;
                //notice.LeadingActor = senderUser.DisplayName;
                //notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId));
                //notice.RelativeObjectId = sender.TopicId;
                //notice.RelativeObjectName = StringUtility.Trim(entity.TopicName, 64);
                //notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().TopicHome(entity.TopicKey));
                //notice.TemplateName = NoticeTemplateNames.Instance().MemberApplyApproved();
                //noticeService.Create(notice);
            }
        }
        /// <summary>
        /// 转换成groupEntity类型
        /// </summary>
        /// <returns></returns>
        public TopicEntity AsTopicEntity()
        {
            CategoryService categoryService = new CategoryService();
            TopicEntity topicEntity = null;

            //创建专题
            if (this.TopicId == 0)
            {
                topicEntity = TopicEntity.New();
                topicEntity.UserId = UserContext.CurrentUser.UserId;
                topicEntity.DateCreated = DateTime.UtcNow;
                topicEntity.TopicKey = this.TopicKey;
            }
            //编辑专题
            else
            {
                TopicService topicService = new TopicService();
                topicEntity = topicService.Get(this.TopicId);
            }
            topicEntity.IsPublic = this.IsPublic;
            topicEntity.TopicName = this.TopicName;
            if (Logo != null)
            {
                topicEntity.Logo = this.Logo;
            }
            topicEntity.Description = Formatter.FormatMultiLinePlainTextForStorage(this.Description == null ? string.Empty : this.Description, true);
            topicEntity.AreaCode = this.AreaCode??string.Empty;
            topicEntity.JoinWay = this.JoinWay;
            topicEntity.EnableMemberInvite = this.EnableMemberInvite;
            //topickey 去掉空格,变为小写字母
            topicEntity.TopicKey = this.TopicKey.ToLower().Replace(" ","-");

            if (JoinWay == TopicJoinWay.ByQuestion)
            {
                topicEntity.Question = this.Question;
                topicEntity.Answer = this.Answer;
            }
            return topicEntity;
        }
        void IThemeResolver.IncludeStyle(RequestContext controllerContext)
        {
            string spaceKey = controllerContext.GetParameterFromRouteDataOrQueryString("SpaceKey");
            TopicEntity topic = new TopicService().Get(spaceKey);
            if (topic == null)
                return;
            PresentArea presentArea = new PresentAreaService().Get(PresentAreaKeysOfExtension.TopicSpace);
            if (presentArea == null)
                return;


            string themeKey = null;
            string appearanceKey = null;

            IPageResourceManager resourceManager = DIContainer.ResolvePerHttpRequest<IPageResourceManager>();
            if (!presentArea.EnableThemes)
            {
                string themeCssPath = string.Format("{0}/{1}/theme.css", presentArea.ThemeLocation, presentArea.DefaultThemeKey);
                string appearanceCssPath = string.Format("{0}/{1}/Appearances/{2}/appearance.css", presentArea.ThemeLocation, presentArea.DefaultThemeKey, presentArea.DefaultAppearanceKey);

                resourceManager.IncludeStyle(themeCssPath);
                resourceManager.IncludeStyle(appearanceCssPath);
                return;
            }

            if (topic.IsUseCustomStyle)
            {
                var customStyleEntity = new CustomStyleService().Get(presentArea.PresentAreaKey, topic.TopicId);
                if (customStyleEntity == null)
                    return;
                CustomStyle customStyle = customStyleEntity.CustomStyle;
                if (customStyle == null)
                    return;
                string themeCssPath = string.Format("{0}/Custom/theme{1}.css", presentArea.ThemeLocation, customStyle.IsDark ? "-deep" : "");
                string appearanceCssPath = SiteUrls.Instance().CustomStyle(presentArea.PresentAreaKey, topic.TopicId);
                resourceManager.IncludeStyle(themeCssPath);
                resourceManager.IncludeStyle(appearanceCssPath);
                StringBuilder builder = new StringBuilder();
                builder.AppendLine(".tn-page-bg{");
                if (customStyle.IsUseBackgroundImage && !string.IsNullOrEmpty(customStyle.BackgroundImageStyle.Url))
                {
                    builder.AppendLine("background-image:url('" + customStyle.BackgroundImageStyle.Url + @"');");
                    builder.AppendFormat("background-repeat:{0};\n", customStyle.BackgroundImageStyle.IsRepeat ? "repeat" : "no-repeat");
                    builder.AppendFormat("background-attachment:{0};\n", customStyle.BackgroundImageStyle.IsFix ? "fixed" : "scroll");
                    string position = "center";
                    switch (customStyle.BackgroundImageStyle.BackgroundPosition)
                    {
                        case BackgroundPosition.Left:
                            position = "left";
                            break;
                        case BackgroundPosition.Center:
                            position = "center";
                            break;
                        case BackgroundPosition.Right:
                            position = "right";
                            break;
                        default:
                            position = "center";
                            break;
                    }
                    builder.AppendFormat("background-position:{0} top;\n", position);
                }

                builder.AppendLine("}");

                resourceManager.RegisterStyleBlock(builder.ToString());
            }
            else
            {
                string[] themeAppearanceArray = topic.ThemeAppearance.Split(',');
                var appearance = new ThemeService().GetThemeAppearance(PresentAreaKeysOfExtension.TopicSpace, topic.ThemeAppearance);

                if (appearance != null && themeAppearanceArray.Count() == 2)
                {
                    themeKey = themeAppearanceArray[0];
                    appearanceKey = themeAppearanceArray[1];
                }
                else
                {
                    themeKey = presentArea.DefaultThemeKey;
                    appearanceKey = presentArea.DefaultAppearanceKey;
                }

                string themeCssPath = string.Format("{0}/{1}/theme.css", presentArea.ThemeLocation, themeKey);
                string appearanceCssPath = string.Format("{0}/{1}/Appearances/{2}/appearance.css", presentArea.ThemeLocation, themeKey, appearanceKey);

                resourceManager.IncludeStyle(themeCssPath);
                resourceManager.IncludeStyle(appearanceCssPath);
            }


        }