public void UnassignRole(User organization, Role role = null)
        {
            if (organization == null)
                throw new ArgumentNullException("organization");
            Expression<Func<OrganizationRole, bool>> specExpression;
            if (role == null)
                specExpression = ur => ur.OrganizationId == organization.Id;
            else
                specExpression = ur => ur.OrganizationId == organization.Id && ur.RoleId == role.Id;

            var userRole = _organizationRoleRepository.GetFiltered(specExpression).FirstOrDefault();

            if (userRole != null)
            {
                _organizationRoleRepository.Remove(userRole);
            }
        }
Exemple #2
0
        public void UnassignRole(User user, Role role = null)
        {
            if (user == null)
                throw new ArgumentNullException("user");
            Expression<Func<UserRole, bool>> specExpression;
            if (role == null)
                specExpression = ur => ur.UserId == user.Id;
            else
                specExpression = ur => ur.UserId == user.Id && ur.RoleId == role.Id;

            var userRole = _userRoleRepository.GetFiltered(specExpression).FirstOrDefault();

            if (userRole != null)
            {
                _userRoleRepository.Remove(userRole);
            }
        }
Exemple #3
0
 /// <summary>
 ///     创建角色
 /// </summary>
 /// <param name="name">名称</param>
 /// <param name="decription">描述</param>
 /// <param name="code">代码</param>
 /// <param name="levelCode">层级代码</param>
 public static Role CreateRole(string name, string decription = null, string code = null, string levelCode = null)
 {
     if (string.IsNullOrEmpty(name))
     {
         throw new ArgumentNullException("name");
     }
     var role = new Role
     {
         Name = name,
         Code = code,
         LevelCode = levelCode,
         Description = decription,
         CreateDate = DateTime.Now,
     };
     role.GenerateNewIdentity();
     return role;
 }
Exemple #4
0
        public void UnassignRole(FunctionItem function, Role role = null)
        {
            if (function == null)
                throw new ArgumentNullException("function");
            Expression<Func<RoleFunction, bool>> specExpression;
            if (role == null)
                specExpression = ur => ur.FunctionItemId == function.Id;
            else
                specExpression = ur => ur.FunctionItemId == function.Id && ur.RoleId == role.Id;

            var roleFunction = _roleFunctionRepository.GetFiltered(specExpression).FirstOrDefault();

            if (roleFunction != null)
            {
                _roleFunctionRepository.Remove(roleFunction);
            }
        }
 public OrganizationRole AssignRole(Organization organization, Role role)
 {
     if (organization == null)
         throw new ArgumentNullException("organization");
     if (role == null)
         throw new ArgumentNullException("role");
     var organizationRole = _organizationRoleRepository.GetFiltered(p => p.OrganizationId == organization.Id)
         .FirstOrDefault();
     if (organizationRole == null)
     {
         organizationRole = new OrganizationRole(organization.Id, role.Id);
         _organizationRoleRepository.Add(organizationRole);
     }
     else
     {
         organizationRole.SetRoleId(role.Id);
         _organizationRoleRepository.Modify(organizationRole);
     }
     return organizationRole;
 }
Exemple #6
0
 public UserRole AssignRole(User user, Role role)
 {
     if (user == null)
         throw new ArgumentNullException("user");
     if (role == null)
         throw new ArgumentNullException("role");
     var userRole = _userRoleRepository.GetFiltered(p => p.UserId == user.Id)
         .FirstOrDefault();
     if (userRole == null)
     {
         userRole = new UserRole(user.Id, role.Id);
         _userRoleRepository.Add(userRole);
     }
     else
     {
         //userRole.SetRoleId(role.Id);
         _userRoleRepository.Modify(userRole);
     }
     return userRole;
 }
Exemple #7
0
 public RoleFunction AssignRole(FunctionItem function, Role role)
 {
     if (function == null)
         throw new ArgumentNullException("function");
     if (role == null)
         throw new ArgumentNullException("role");
     var roleFunction = _roleFunctionRepository.GetFiltered(p => p.FunctionItemId == function.Id)
         .FirstOrDefault();
     if (roleFunction == null)
     {
         roleFunction = new RoleFunction(function.Id, role.Id);
         _roleFunctionRepository.Add(roleFunction);
     }
     else
     {
         //roleFunction.SetRoleId(role.Id);
         _roleFunctionRepository.Modify(roleFunction);
     }
     return roleFunction;
 }
Exemple #8
0
 /// <summary>
 ///     插入角色功能
 /// </summary>
 /// <param name="role">角色</param>
 /// <param name="roleFunctionDto">角色功能DTO</param>
 private void InsertRoleFunction(Role role, RoleFunctionDTO roleFunctionDto)
 {
     var persist = _roleFunctionRepository.Get(roleFunctionDto.Id);
     if (persist != null) return;
     var roleFunction = new RoleFunction(role.Id, roleFunctionDto.FunctionItemId);
     _roleFunctionRepository.Add(roleFunction);
 }