Esempio n. 1
0
        /// <summary>
        /// 授予角色
        /// </summary>
        /// <param name="role"></param>
        public Role GiveRole(Role role)
        {
            if (!Role.GetRoleList().Exists(r => r.Id == role.Id))
            {
                throw new Exception("授予的角色不存在");
            }
            if (RoleOrganizationInfoRepo.Read().Exists(ro => ro.RoleId == role.Id && ro.OrganizationId == this.Id))
            {
                return role;
            }

            //检查互斥
            List<Role> linkRoleList = this.LinkRoleList;
            foreach (Role linkRole in linkRoleList)
            {
                if (RoleMutex.CheckMutex(role, linkRole, RoleMutexType.Static))
                {
                    throw new Exception("授予的角色和当前组织或其父级或其子级的角色存在静态互斥关系");
                }
            }

            RoleOrganizationInfo roleOrganizationInfo = new RoleOrganizationInfo();
            roleOrganizationInfo.RoleId = role.Id;
            roleOrganizationInfo.OrganizationId = this.Id;
            RoleOrganizationInfoRepo.Save(roleOrganizationInfo);
            return role;
        }
Esempio n. 2
0
 /// <summary>
 /// 取消角色
 /// </summary>
 /// <param name="role"></param>
 public Role CancelRole(Role role)
 {
     RoleOrganizationInfo roleOrganizationInfo = new RoleOrganizationInfo();
     roleOrganizationInfo.RoleId = role.Id;
     roleOrganizationInfo.OrganizationId = this.Id;
     RoleOrganizationInfoRepo.Delete(roleOrganizationInfo);
     return role;
 }