Example #1
0
 /// <summary>
 /// 上传Logo
 /// </summary>
 /// <param name="groupId">群组Id</param>
 /// <param name="stream">Logo文件流</param>
 public void UploadLogo(long groupId, Stream stream)
 {
     //按现在设计应该用LogoService,但是感觉LogoService没什么必要(重构Logo/Image直连后再定)
     if (stream != null)
     {
         GroupEntity group       = this.Get(groupId);
         LogoService logoService = new LogoService(TenantTypeIds.Instance().Group());
         group.Logo = logoService.UploadLogo(groupId, stream);
         groupRepository.Update(group);
         EventBus <GroupEntity> .Instance().OnAfter(group, new CommonEventArgs(EventOperationType.Instance().Update()));
     }
 }
Example #2
0
        /// <summary>
        /// 把用户加入到一组角色中
        /// </summary>
        public void AddUserToRoles(long userId, List <string> roleNames)
        {
            if (roleNames == null)
            {
                return;
            }

            IEnumerable <string> oldRoleNames = GetRolesOfUser(userId).Select(n => n.RoleName);
            bool nameIsChange = false;

            //done:zhangp,by zhengw:以下代码有问题,当oldRoleNames.Count()为0时,不会为用户添加角色
            //foreach (var roleName in roleNames)
            //{
            //    if (oldRoleNames.Any(r => !r.Equals(roleName, StringComparison.InvariantCultureIgnoreCase)))
            //        nameIsChange = true;
            //}
            //以下为nameIsChange赋值的代码为郑伟添加
            nameIsChange = roleNames.Except(oldRoleNames).Count() > 0;

            if (nameIsChange)
            {
                userInRoleRepository.AddUserToRoles(userId, roleNames);
                List <UserInRole> newUsersInRoles = new List <UserInRole>();
                foreach (var r in roleNames)
                {
                    newUsersInRoles.Add(new UserInRole()
                    {
                        UserId = userId, RoleName = r
                    });
                }
                EventBus <UserInRole> .Instance().OnBatchAfter(newUsersInRoles, new CommonEventArgs(EventOperationType.Instance().Update()));
            }
        }
Example #3
0
        /// <summary>
        /// 移除用户的一个角色
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="roleName">角色名称</param>
        public void RemoveUserFromRole(long userId, string roleName)
        {
            Role role = Get(roleName);

            if (role != null)
            {
                UserInRole userInRole = new UserInRole()
                {
                    UserId   = userId,
                    RoleName = role.RoleName
                };

                userInRoleRepository.Delete(userId, roleName);

                EventBus <UserInRole> .Instance().OnAfter(userInRole, new CommonEventArgs(EventOperationType.Instance().Delete()));
            }
        }
Example #4
0
        /// <summary>
        /// 更新用户资料(基本资料)
        /// </summary>
        /// <param name="userProfile">用户资料</param>
        public void Update(UserProfile userProfile)
        {
            if (userProfile == null)
            {
                return;
            }
            EventBus <UserProfile> .Instance().OnBefore(userProfile, new CommonEventArgs(EventOperationType.Instance().Update()));

            profileRepository.Update(userProfile);
            profileRepository.UpdateIntegrity(userProfile.UserId);

            User user = DIContainer.Resolve <UserService>().GetFullUser(userProfile.UserId);

            if (!user.HasAvatar)
            {
                string avatarFileName = "avatar";
                if (userProfile.Gender == GenderType.NotSet)
                {
                    avatarFileName += "_default";
                }
                else
                {
                    avatarFileName += "_" + userProfile.Gender.ToString();
                }
                long            dateAvatar     = DateTime.UtcNow.Ticks;
                IUserRepository userRepository = DIContainer.Resolve <IUserRepository>();
                userRepository.UpdateAvatar(user, dateAvatar, avatarFileName);
            }

            EventBus <UserProfile> .Instance().OnAfter(userProfile, new CommonEventArgs(EventOperationType.Instance().Update()));
        }
        /// <summary>
        /// 通知处理程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        private void GroupMemberApplyNoticeModule_After(GroupMemberApply sender, CommonEventArgs eventArgs)
        {
            GroupService groupService = new GroupService();
            GroupEntity  entity       = groupService.Get(sender.GroupId);

            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 == GroupMemberApplyStatus.Pending)
                {
                    List <long> toUserIds = new List <long>();
                    toUserIds.Add(entity.UserId);
                    toUserIds.AddRange(entity.GroupManagers.Select(n => n.UserId));
                    foreach (var toUserId in toUserIds)
                    {
                        //申请加入群组的请求
                        if (!groupService.IsMember(sender.GroupId, sender.UserId))
                        {
                            invitation = Invitation.New();
                            invitation.ApplicationId      = GroupConfig.Instance().ApplicationId;
                            invitation.InvitationTypeKey  = InvitationTypeKeys.Instance().ApplyJoinGroup();
                            invitation.UserId             = toUserId;
                            invitation.SenderUserId       = sender.UserId;
                            invitation.Sender             = senderUser.DisplayName;
                            invitation.SenderUrl          = SiteUrls.Instance().SpaceHome(sender.UserId);
                            invitation.RelativeObjectId   = sender.GroupId;
                            invitation.RelativeObjectName = entity.GroupName;
                            invitation.RelativeObjectUrl  = SiteUrls.FullUrl(SiteUrls.Instance().GroupHome(entity.GroupKey));
                            invitation.Remark             = sender.ApplyReason;
                            invitationService.Create(invitation);
                        }
                    }
                }
            }

            string noticeTemplateName = string.Empty;

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

            if (string.IsNullOrEmpty(noticeTemplateName))
            {
                return;
            }

            notice = Notice.New();

            notice.UserId        = sender.UserId;
            notice.ApplicationId = GroupConfig.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.GroupId;
            notice.RelativeObjectName = StringUtility.Trim(entity.GroupName, 64);
            notice.RelativeObjectUrl  = SiteUrls.FullUrl(SiteUrls.Instance().GroupHome(entity.GroupKey));
            notice.TemplateName       = noticeTemplateName;
            noticeService.Create(notice);
        }
Example #6
0
        /// <summary>
        /// 添加教育经历
        /// </summary>
        /// <param name="educationExperience"><see cref="EducationExperience"/></param>
        /// <returns>创建成功返回true,否则返回false</returns>
        public bool CreateEducationExperience(EducationExperience educationExperience)
        {
            if (educationExperience == null)
            {
                return(false);
            }

            long affectId = Convert.ToInt64(educationExperienceRepository.Insert(educationExperience));

            UserProfile userProfile = profileRepository.Get(educationExperience.UserId);

            EventBus <UserProfile> .Instance().OnAfter(userProfile, new CommonEventArgs(EventOperationType.Instance().Update()));

            if (affectId > 0)
            {
                profileRepository.UpdateIntegrity(educationExperience.UserId);
                return(true);
            }

            return(false);
        }
Example #7
0
        /// <summary>
        /// 删除教育经历
        /// </summary>
        /// <param name="id">教育经历Id</param>
        /// <returns>删除成功返回true,否则返回false</returns>
        public bool DeleteEducationExperience(long id)
        {
            if (id == 0)
            {
                return(false);
            }
            EducationExperience educationExperience = educationExperienceRepository.Get(id);

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

            //OK
            if (GetEducationExperiences(educationExperience.UserId).Count() == 1)
            {
                educationExperienceRepository.DeleteByEntityId(id);
                profileRepository.UpdateIntegrity(educationExperience.UserId);
            }
            else
            {
                educationExperienceRepository.DeleteByEntityId(id);
            }


            UserProfile userProfile = profileRepository.Get(educationExperience.UserId);

            EventBus <UserProfile> .Instance().OnAfter(userProfile, new CommonEventArgs(EventOperationType.Instance().Update()));

            return(true);
        }
Example #8
0
        /// <summary>
        /// 移除群组成员
        /// </summary>
        /// <param name="groupId">群组Id</param>
        /// <param name="userId">用户Id</param>
        public void DeleteGroupMember(long groupId, long userId)
        {
            GroupMember groupMember = groupMemberRepository.GetMember(groupId, userId);

            if (groupMember == null)
            {
                return;
            }

            int affectCount = groupMemberRepository.Delete(groupMember);

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

                //用户的参与群组数-1
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(userId, OwnerDataKeys.Instance().JoinedGroupCount(), -1);
            }
        }
Example #9
0
        /// <summary>
        /// 设置/取消 群组管理员
        /// </summary>
        /// <param name="groupId">群组Id</param>
        /// <param name="userId">用户Id</param>
        /// <param name="isManager">是否管理员</param>
        public bool SetManager(long groupId, long userId, bool isManager)
        {
            //设计要点:
            //1、userId必须是groupId成员
            GroupMember member = groupMemberRepository.GetMember(groupId, userId);

            if (member == null)
            {
                return(false);
            }
            if (member.IsManager == isManager)
            {
                return(false);
            }
            member.IsManager = isManager;
            groupMemberRepository.Update(member);
            if (isManager)
            {
                EventBus <GroupMember> .Instance().OnAfter(member, new CommonEventArgs(EventOperationType.Instance().SetGroupManager()));
            }
            else
            {
                EventBus <GroupMember> .Instance().OnAfter(member, new CommonEventArgs(EventOperationType.Instance().CancelGroupManager()));
            }
            return(true);
        }
Example #10
0
        /// <summary>
        /// 创建群组
        /// </summary>
        /// <param name="userId">当前操作人</param>
        /// <param name="group"><see cref="GroupEntity"/></param>
        /// <param name="logoFile">群组标识图</param>
        /// <returns>创建成功返回true,失败返回false</returns>
        public bool Create(long userId, GroupEntity group)
        {
            //设计要点
            //1、使用AuditService设置审核状态;
            //2、需要触发的事件参见《设计说明书-文章》
            //3、单独调用标签服务设置标签
            //4、使用 IdGenerator.Next() 生成GroupId
            EventBus <GroupEntity> .Instance().OnBefore(group, new CommonEventArgs(EventOperationType.Instance().Create()));

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

            long.TryParse(groupRepository.Insert(group).ToString(), out id);

            if (id > 0)
            {
                EventBus <GroupEntity> .Instance().OnAfter(group, new CommonEventArgs(EventOperationType.Instance().Create()));

                EventBus <GroupEntity, AuditEventArgs> .Instance().OnAfter(group, new AuditEventArgs(null, group.AuditStatus));

                //用户的创建群组数+1
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(group.UserId, OwnerDataKeys.Instance().CreatedGroupCount(), 1);
            }
            return(id > 0);
        }
Example #11
0
        /// <summary>
        /// 增加群组成员
        /// </summary>
        /// <param name="groupMember"></param>
        public void CreateGroupMember(GroupMember groupMember)
        {
            //设计要点:
            //1、同一个群组不允许用户重复加入
            //2、群主不允许成为群组成员
            if (IsMember(groupMember.GroupId, groupMember.UserId))
            {
                return;
            }
            if (IsOwner(groupMember.GroupId, groupMember.UserId))
            {
                return;
            }
            long id = 0;

            long.TryParse(groupMemberRepository.Insert(groupMember).ToString(), out id);

            if (id > 0)
            {
                EventBus <GroupMember> .Instance().OnAfter(groupMember, new CommonEventArgs(EventOperationType.Instance().Create()));

                //用户的参与群组数+1
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(groupMember.UserId, OwnerDataKeys.Instance().JoinedGroupCount(), 1);
            }
        }
Example #12
0
        /// <summary>
        /// 删除群组加入申请
        /// </summary>
        /// <param name="id">申请Id</param>
        public void DeleteGroupMemberApply(long id)
        {
            GroupMemberApply apply = groupMemberApplyRepository.Get(id);

            if (apply == null)
            {
                return;
            }

            int affectCount = groupMemberApplyRepository.Delete(apply);

            if (affectCount > 0)
            {
                EventBus <GroupMemberApply> .Instance().OnAfter(apply, new CommonEventArgs(EventOperationType.Instance().Delete()));
            }
        }
Example #13
0
        /// <summary>
        /// 接受/拒绝群组加入申请
        /// </summary>
        /// <param name="groupIds">申请Id列表</param>
        /// <param name="isApproved">是否接受</param>
        public void ApproveGroupMemberApply(IEnumerable <long> applyIds, bool isApproved)
        {
            //设计要点:
            //1、仅允许对待处理状态的申请变更状态;
            //2、通过批准的申请,直接创建GroupMember
            IEnumerable <GroupMemberApply> groupMemberApplies = groupMemberApplyRepository.PopulateEntitiesByEntityIds(applyIds);
            GroupMemberApplyStatus         applyStatus        = isApproved ? GroupMemberApplyStatus.Approved : GroupMemberApplyStatus.Disapproved;
            string operationType = isApproved ? EventOperationType.Instance().Approved() : EventOperationType.Instance().Disapproved();

            foreach (var apply in groupMemberApplies)
            {
                if (apply.ApplyStatus != GroupMemberApplyStatus.Pending)
                {
                    continue;
                }



                apply.ApplyStatus = applyStatus;
                groupMemberApplyRepository.Update(apply);



                EventBus <GroupMemberApply> .Instance().OnAfter(apply, new CommonEventArgs(operationType));

                if (isApproved)
                {
                    GroupMember member = GroupMember.New();
                    member.UserId  = apply.UserId;
                    member.GroupId = apply.GroupId;
                    CreateGroupMember(member);
                }
            }
        }
Example #14
0
        /// <summary>
        /// 申请加入群组
        /// </summary>
        /// <param name="groupMemberApply">群组加入申请</param>
        public void CreateGroupMemberApply(GroupMemberApply groupMemberApply)
        {
            //设计要点:
            //1、用户对同一个群组不允许有多个待处理的加入申请


            if (groupMemberApply == null)
            {
                return;
            }
            if (IsApplied(groupMemberApply.UserId, groupMemberApply.GroupId))
            {
                return;
            }
            long id = 0;

            long.TryParse(groupMemberApplyRepository.Insert(groupMemberApply).ToString(), out id);

            if (id > 0)
            {
                EventBus <GroupMemberApply> .Instance().OnAfter(groupMemberApply, new CommonEventArgs(EventOperationType.Instance().Create()));
            }
        }
        private void FollowUser_After(FollowEntity followEntity, CommonEventArgs eventArgs)
        {
            if (eventArgs.EventOperationType == EventOperationType.Instance().Update() || eventArgs.EventOperationType == EventOperationType.Instance().Delete())
            {
                if (searcher == null)
                {
                    searcher = (FollowUserSearcher)SearcherFactory.GetSearcher(FollowUserSearcher.CODE);
                }

                searcher.Update(followEntity.UserId);
            }
        }
Example #16
0
 /// <summary>
 /// 删除和更新标签时触发
 /// </summary>
 private void DeleteUpdateTags_Before(Tag sender, CommonEventArgs eventArgs)
 {
     if (sender.TenantTypeId == TenantTypeIds.Instance().BlogThread())
     {
         if (eventArgs.EventOperationType == EventOperationType.Instance().Delete() || eventArgs.EventOperationType == EventOperationType.Instance().Update())
         {
             //根据标签获取所有使用该标签的(内容项)日志
             IEnumerable <long> blogThreadIds = tagService.GetItemIds(sender.TagName, null);
             if (blogSearcher == null)
             {
                 blogSearcher = (BlogSearcher)SearcherFactory.GetSearcher(BlogSearcher.CODE);
             }
             blogSearcher.Update(blogService.GetBlogThreads(blogThreadIds));
         }
     }
 }
Example #17
0
        /// <summary>
        /// 删除用户资料
        /// </summary>
        /// <param name="userProfile">用户资料</param>
        /// <returns>删除成功返回true,否则返回false</returns>
        public bool Delete(long userId)
        {
            UserProfile userProfile = profileRepository.Get(userId);

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

            profileRepository.Delete(userProfile);
            IEnumerable <EducationExperience> educationExperiences = GetEducationExperiences(userId);

            if (educationExperiences != null)
            {
                foreach (var educationExperience in educationExperiences)
                {
                    educationExperienceRepository.Delete(educationExperience);
                }
            }

            IEnumerable <WorkExperience> workExperiences = GetWorkExperiences(userId);

            if (workExperiences != null)
            {
                foreach (var workExperience in workExperiences)
                {
                    workExperienceRepository.Delete(workExperience);
                }
            }

            //通过UserId  删除个人标签
            TagService tagService = new TagService(TenantTypeIds.Instance().UserProfile());

            tagService.DeleteOwnerTag(userId);
            EventBus <UserProfile> .Instance().OnAfter(userProfile, new CommonEventArgs(EventOperationType.Instance().Delete()));

            //同时删除教育经历、工作经历、个人标签、头像文件等
            return(true);
        }
Example #18
0
 /// <summary>
 /// 删除和更新分类时触发
 /// </summary>
 private void DeleteUpdateCategories_Before(Category sender, CommonEventArgs eventArgs)
 {
     if (sender.TenantTypeId == TenantTypeIds.Instance().BlogThread())
     {
         if (eventArgs.EventOperationType == EventOperationType.Instance().Delete() || eventArgs.EventOperationType == EventOperationType.Instance().Update())
         {
             IEnumerable <long> blogThreadIds = categoryService.GetItemIds(sender.CategoryId, false);
             if (blogSearcher == null)
             {
                 blogSearcher = (BlogSearcher)SearcherFactory.GetSearcher(BlogSearcher.CODE);
             }
             blogSearcher.Update(blogService.GetBlogThreads(blogThreadIds));
         }
     }
 }
Example #19
0
        /// <summary>
        /// 更新教育经历
        /// </summary>
        /// <param name="educationExperience"><see cref="EducationExperience"/></param>
        public void UpdateEducationExperience(EducationExperience educationExperience)
        {
            if (educationExperience == null)
            {
                return;
            }
            educationExperienceRepository.Update(educationExperience);

            UserProfile userProfile = profileRepository.Get(educationExperience.UserId);

            EventBus <UserProfile> .Instance().OnAfter(userProfile, new CommonEventArgs(EventOperationType.Instance().Update()));
        }
Example #20
0
 /// <summary>
 /// 删除和更新标签时触发
 /// </summary>
 private void DeleteUpdateTags_Before(Tag sender, CommonEventArgs eventArgs)
 {
     if (sender.TenantTypeId == TenantTypeIds.Instance().ContentItem())
     {
         if (eventArgs.EventOperationType == EventOperationType.Instance().Delete() || eventArgs.EventOperationType == EventOperationType.Instance().Update())
         {
             //根据标签获取所有使用该标签的(内容项)资讯
             IEnumerable <long> cmsThreadIds = tagService.GetItemIds(sender.TagName, null);
             if (cmsSearcher == null)
             {
                 cmsSearcher = (CmsSearcher)SearcherFactory.GetSearcher(CmsSearcher.CODE);
             }
             cmsSearcher.Update(contentItemService.GetContentItems(cmsThreadIds));
         }
     }
 }
Example #21
0
        /// <summary>
        /// 创建用户资料(基本资料)
        /// </summary>
        /// <param name="userProfile">用户资料</param>
        /// <returns>创建成功返回true,否则返回false</returns>
        public bool Create(UserProfile userProfile)
        {
            if (userProfile == null)
            {
                return(false);
            }

            //需要添加检查是否存在的方法
            //如果存在则更新用户资料
            if (profileRepository.UserIdIsExist(userProfile.UserId))
            {
                this.Update(userProfile);
                return(false);
            }

            EventBus <UserProfile> .Instance().OnBefore(userProfile, new CommonEventArgs(EventOperationType.Instance().Create()));

            long userId = Convert.ToInt64(profileRepository.Insert(userProfile));

            profileRepository.UpdateIntegrity(userProfile.UserId);

            EventBus <UserProfile> .Instance().OnAfter(userProfile, new CommonEventArgs(EventOperationType.Instance().Create()));

            return(userId > 0);
        }
Example #22
0
        /// <summary>
        /// 资讯增量索引
        /// </summary>
        private void ContentItem_After(ContentItem cms, CommonEventArgs eventArgs)
        {
            if (cms == null)
            {
                return;
            }

            if (cmsSearcher == null)
            {
                cmsSearcher = (CmsSearcher)SearcherFactory.GetSearcher(CmsSearcher.CODE);
            }

            //添加索引
            if (eventArgs.EventOperationType == EventOperationType.Instance().Create())
            {
                cmsSearcher.Insert(cms);
            }

            //删除索引
            if (eventArgs.EventOperationType == EventOperationType.Instance().Delete())
            {
                cmsSearcher.Delete(cms.ContentItemId);
            }

            //更新索引
            if (eventArgs.EventOperationType == EventOperationType.Instance().Update() || eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved())
            {
                cmsSearcher.Update(cms);
            }
        }
Example #23
0
        /// <summary>
        /// 取消订阅
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="objectId">被订阅对象Id</param>
        /// <returns>true-取消成功,false-取消失败</returns>
        public bool CancelSubscribe(long objectId, long userId)
        {
            EventBus <long, SubscribeEventArgs> .Instance().OnBefore(objectId, new SubscribeEventArgs(EventOperationType.Instance().Delete(), tenantTypeId, userId));

            bool result = favoriteRepository.CancelFavorited(objectId, userId, tenantTypeId);

            EventBus <long, SubscribeEventArgs> .Instance().OnAfter(objectId, new SubscribeEventArgs(EventOperationType.Instance().Delete(), tenantTypeId, userId));

            return(result);
        }
Example #24
0
        /// <summary>
        /// 设置应用启用禁用状态
        /// </summary>
        /// <param name="applicationId">applicationId</param>
        /// <param name="isEnabled">是否启用</param>
        /// <remarks>设置成功返回true,设置失败返回false</remarks>
        public bool SetStatus(int applicationId, bool isEnabled)
        {
            ApplicationModel applicationModel = applicationRepository.Get(applicationId);

            if (applicationModel != null && applicationModel.IsEnabled != isEnabled)
            {
                EventBus <ApplicationModel> .Instance().OnBefore(applicationModel, new CommonEventArgs(EventOperationType.Instance().Update(), applicationId));

                applicationModel.IsEnabled = isEnabled;
                applicationRepository.Update(applicationModel);
                EventBus <ApplicationModel> .Instance().OnAfter(applicationModel, new CommonEventArgs(EventOperationType.Instance().Update(), applicationId));

                ICacheService cacheService = DIContainer.Resolve <ICacheService>();
                if (cacheService.EnableDistributedCache)
                {
                    cacheService.Remove(GetCacheKey_AllApplicationBases());
                }
                else
                {
                    ApplicationBase app = Get(applicationId);
                    app.IsEnabled = isEnabled;
                }
                return(true);
            }

            return(false);
        }
Example #25
0
        /// <summary>
        /// 设置审核设置
        /// </summary>
        /// <param name="eventId">活动Id</param>
        /// <param name="isApproved">审核状态</param>
        public void UpdateAuditStatus(long voteId, bool isApproved)
        {
            AuditStatus auditStatus   = isApproved ? AuditStatus.Success : AuditStatus.Fail;
            VoteThread  voteThread    = voteThreadRepository.Get(voteId);
            string      operationType = isApproved ? EventOperationType.Instance().Approved() : EventOperationType.Instance().Disapproved();

            if (voteThread != null && voteThread.AuditStatus != auditStatus)
            {
                AuditStatus oldAuditStatus = voteThread.AuditStatus;
                voteThread.AuditStatus = auditStatus;
                voteThreadRepository.Update(voteThread);
                //触发事件
                EventBus <VoteThread> .Instance().OnAfter(voteThread, new CommonEventArgs(operationType));

                EventBus <VoteThread, AuditEventArgs> .Instance().OnAfter(voteThread, new AuditEventArgs(oldAuditStatus, auditStatus));
            }
        }
Example #26
0
        /// <summary>
        /// 为呈现区域实例安装应用
        /// </summary>
        /// <param name="presentAreaKey">呈现区域标识</param>
        /// <param name="ownerId">呈现区域实例拥有者Id</param>
        /// <param name="applicationId">applicationId</param>
        /// <returns>安装成功返回true,安装失败返回false</returns>
        public bool Install(string presentAreaKey, long ownerId, int applicationId)
        {
            ApplicationBase app = Get(applicationId);

            if (app == null || !app.IsEnabled)
            {
                return(false);
            }

            if (!IsAvailable(presentAreaKey, applicationId))
            {
                return(false);
            }

            if (IsInstalled(presentAreaKey, ownerId, applicationId))
            {
                return(false);
            }

            EventBus <ApplicationBase> .Instance().OnBefore(app, new CommonEventArgs(EventOperationType.Instance().Create(), applicationId));

            if (app.Install(presentAreaKey, ownerId))
            {
                //添加安装记录
                ApplicationInPresentAreaInstallation applicationInstallation = new ApplicationInPresentAreaInstallation()
                {
                    PresentAreaKey = presentAreaKey,
                    OwnerId        = ownerId,
                    ApplicationId  = applicationId
                };
                applicationInstallationRepository.Insert(applicationInstallation);

                //安装应用的导航
                DIContainer.Resolve <NavigationService>().InstallPresentAreaNavigationsOfApplication(presentAreaKey, ownerId, applicationId);
                EventBus <ApplicationBase> .Instance().OnAfter(app, new CommonEventArgs(EventOperationType.Instance().Create(), applicationId));

                return(true);
            }

            return(false);
        }
Example #27
0
        /// <summary>
        /// 给用户添加角色
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="roleName">角色名称</param>
        public void AddUserToRole(long userId, string roleName)
        {
            Role role = Get(roleName);

            if (role != null)
            {
                if (!role.ConnectToUser)
                {
                    return;
                }

                UserInRole userInRole = new UserInRole()
                {
                    UserId   = userId,
                    RoleName = role.RoleName
                };

                userInRoleRepository.Insert(userInRole);

                EventBus <UserInRole> .Instance().OnAfter(userInRole, new CommonEventArgs(EventOperationType.Instance().Create()));
            }
        }
Example #28
0
        /// <summary>
        /// 为呈现区域实例卸载应用
        /// </summary>
        /// <remarks>
        /// <list type="bullet">
        ///     <item>呈现区域的内置应用不允许移除</item>
        ///     <item>未安装的应用移除失败</item>
        /// </list>
        /// </remarks>
        /// <param name="presentAreaKey">呈现区域标识</param>
        /// <param name="ownerId">呈现区域实例拥有者Id</param>
        /// <param name="applicationId">applicationId</param>
        /// <returns>卸载成功返回true,卸载失败返回false</returns>
        public bool UnInstall(string presentAreaKey, long ownerId, int applicationId)
        {
            ApplicationBase app = Get(applicationId);

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

            //呈现区域的内置应用不允许移除
            if (IsBuiltIn(presentAreaKey, applicationId))
            {
                return(false);
            }

            if (!IsInstalled(presentAreaKey, ownerId, applicationId))
            {
                return(false);
            }

            EventBus <ApplicationBase> .Instance().OnBefore(app, new CommonEventArgs(EventOperationType.Instance().Delete(), applicationId));

            if (app.UnInstall(presentAreaKey, ownerId))
            {
                ApplicationInPresentAreaInstallation applicationInstallation = applicationInstallationRepository.Fetch(presentAreaKey, ownerId, applicationId);
                if (applicationInstallation != null)
                {
                    applicationInstallationRepository.DeleteByEntityId(applicationInstallation.Id);

                    //卸载应用的导航
                    DIContainer.Resolve <NavigationService>().UnInstallPresentAreaNavigationsOfApplication(presentAreaKey, ownerId, applicationId);
                    EventBus <ApplicationBase> .Instance().OnAfter(app, new CommonEventArgs(EventOperationType.Instance().Delete(), applicationId));

                    return(true);
                }
            }

            return(false);
        }
Example #29
0
        /// <summary>
        /// 添加收藏
        /// </summary>
        /// <param name="objectId">被收藏对象Id</param>
        /// <param name="userId">用户Id</param>
        /// <returns>true-收藏成功,false-收藏失败</returns>
        public bool Favorite(long objectId, long userId)
        {
            EventBus <long, FavoriteEventArgs> .Instance().OnBefore(objectId, new FavoriteEventArgs(EventOperationType.Instance().Create(), tenantTypeId, userId));

            bool result = favoriteRepository.Favorite(objectId, userId, tenantTypeId);

            EventBus <long, FavoriteEventArgs> .Instance().OnAfter(objectId, new FavoriteEventArgs(EventOperationType.Instance().Create(), tenantTypeId, userId));

            return(result);
        }
Example #30
0
        /// <summary>
        /// 批准/不批准群组
        /// </summary>
        /// <param name="groupId">待被更新的群组Id</param>
        /// <param name="isApproved">是否通过审核</param>
        public void Approve(long groupId, bool isApproved)
        {
            //设计要点
            //1、审核状态未变化不用进行任何操作;
            //2、需要触发的事件参见《设计说明书-群组》;

            GroupEntity group = groupRepository.Get(groupId);

            AuditStatus newAuditStatus = isApproved ? AuditStatus.Success : AuditStatus.Fail;

            if (group.AuditStatus == newAuditStatus)
            {
                return;
            }

            AuditStatus oldAuditStatus = group.AuditStatus;

            group.AuditStatus = newAuditStatus;
            groupRepository.Update(group);

            string operationType = isApproved ? EventOperationType.Instance().Approved() : EventOperationType.Instance().Disapproved();

            EventBus <GroupEntity> .Instance().OnAfter(group, new CommonEventArgs(operationType));

            EventBus <GroupEntity, AuditEventArgs> .Instance().OnAfter(group, new AuditEventArgs(oldAuditStatus, newAuditStatus));
        }