Exemplo n.º 1
0
        public Role GiveRole(Role role)
        {
            if (!PositionInfoRepo.Exists(this.MappingTo<PositionInfo>()))
            {
                throw new Exception("岗位不存在");
            }
            if (!Role.RoleInfoRepo.Exists(role.MappingTo<RoleInfo>()))
            {
                throw new Exception("角色不存在");
            }
            if (RolePositionInfoRepo.Read().Exists(ro => ro.RoleId == role.Id
                && ro.OrganizationId == this.OrganizationId
                && ro.PositionId == this.Id))
            {
                return role;
            }

            //检查互斥,除检查自身外,需检查所有上级组件层叠过来的角色(DeepRoleList 包括上级组件的角色)
            List<Role> linkRoleList = this.DeepRoleList;
            foreach (Role linkRole in linkRoleList)
            {
                if (RoleMutex.CheckMutex(role, linkRole, RoleMutexType.Static))
                {
                    throw new Exception("授予的角色和当前岗位或其所在组织的角色存在静态互斥关系");
                }
            }

            RolePositionInfo rolePositionInfo = new RolePositionInfo();
            rolePositionInfo.RoleId = role.Id;
            rolePositionInfo.OrganizationId = this.OrganizationId;
            rolePositionInfo.PositionId = this.Id;
            RolePositionInfoRepo.Add(rolePositionInfo);
            return role;
        }
Exemplo n.º 2
0
 public Role CancelRole(Role role)
 {
     if (!PositionInfoRepo.Exists(this.MappingTo<PositionInfo>()))
     {
         throw new Exception("岗位不存在");
     }
     RolePositionInfo rolePositionInfo = new RolePositionInfo();
     rolePositionInfo.RoleId = role.Id;
     rolePositionInfo.OrganizationId = this.OrganizationId;
     rolePositionInfo.PositionId = this.Id;
     RolePositionInfoRepo.Delete(rolePositionInfo);
     return role;
 }