BgEngine.Infraestructure.Security.CodeFirstRoleProvider.GetUsersInRole C# (CSharp) Метод

GetUsersInRole() публичный Метод

public GetUsersInRole ( string roleName ) : string[]
roleName string
Результат string[]
        public override string[] GetUsersInRole(string roleName)
        {
            if (string.IsNullOrEmpty(roleName))
                    {
                        throw CreateArgumentNullOrEmptyException("roleName");
                    }
                    using (BlogUnitOfWork context = new BlogUnitOfWork(new ModelContextInit()))
                    {
                        var role = context.Roles.FirstOrDefault(Rl => Rl.RoleName == roleName);
                        if (role == null)
                        {
                            throw new InvalidOperationException("Role not found");
                        }
                        return role.Users.Select(Usr => Usr.Username).ToArray();
                    }
        }

Usage Example

Пример #1
0
 public static string[] GetUsersInRole(string role)
 {
     CodeFirstRoleProvider rp = new CodeFirstRoleProvider();
     return rp.GetUsersInRole(role);
 }