private List <int> GetUserIdsFromNames(MySqlMembershipContext db, string[] usernames) { var userIds = new List <int>(usernames.Length); foreach (var username in usernames) { var id = MySqlSimpleMembershipProvider.GetUserId(db, username); if (id == -1) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Security.Security_NoUserFound, username)); } userIds.Add(id); } return(userIds); }
/// <summary> /// Gets a list of the roles that a specified user is in for the configured applicationName. /// </summary> /// <remarks>Inherited from RoleProvider ==> Forwarded to previous provider if this provider hasn't been initialized</remarks> /// <param name="username">The user to return a list of roles for.</param> /// <returns>A string array containing the names of all the roles that the specified user is in for the configured applicationName.</returns> /// <exception cref="System.InvalidOperationException"></exception> public override string[] GetRolesForUser(string username) { if (!InitializeCalled) { return(PreviousProvider.GetRolesForUser(username)); } using (var db = NewMySqlMembershipContext) { int userId = MySqlSimpleMembershipProvider.GetUserId(db, username); if (userId == -1) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Security.Security_NoUserFound, username)); } var roles = db.UsersInRoles.Where(x => x.UserId == userId) .Select(x => x.Role.RoleName) .ToArray(); return(roles); } }