コード例 #1
0
        public async Task <IEnumerable <UsersMinimalDomain> > GetUsers(RolesEnum rolesType)
        {
            var roleId = await _databaseContext.Roles
                         .Where(r => r.Name.Equals(rolesType.GetDisplayName()))
                         .Select(r => r.Id)
                         .FirstOrDefaultAsync();

            return(await _databaseContext.Roles
                   .Join(_databaseContext.UserRoles,
                         role => role.Id,
                         userRole => userRole.RoleId,
                         (role, userRole) => new { RoleId = role.Id, userRole.UserId })
                   .Join(_databaseContext.Users,
                         userRole => userRole.UserId,
                         user => user.Id,
                         (userRole, user) => new { userRole.RoleId, user.Name, user.Id })
                   .Where(userInfo => userInfo.RoleId == roleId)
                   .Select(userInfo => new UsersMinimalDomain {
                Id = userInfo.Id, UserName = userInfo.Name
            })
                   .ToListAsync().ConfigureAwait(false));
        }
コード例 #2
0
 /// <summary>
 /// Returns a normalized display name of the given role.
 /// </summary>
 public static string GetNormalizedName(this RolesEnum role)
 {
     return(role.GetDisplayName().ToUpper(CultureInfo.InvariantCulture));
 }