Пример #1
0
 // Inherited from RoleProvider ==> Forwarded to previous provider if this provider hasn't been initialized
 public override string[] FindUsersInRole(string roleName, string usernameToMatch)
 {
     if (!InitializeCalled)
     {
         return(PreviousProvider.FindUsersInRole(roleName, usernameToMatch));
     }
     using (var db = ConnectToDatabase())
     {
         // REVIEW: Is there any way to directly get out a string[]?
         List <dynamic> userNames = db.Query(
             @"SELECT u."
             + SafeUserNameColumn
             + " FROM "
             + SafeUserTableName
             + " u, "
             + UsersInRoleTableName
             + " ur, "
             + RoleTableName
             + " r Where (r.RoleName = @0 and ur.RoleId = r.RoleId and ur.UserId = u."
             + SafeUserIdColumn
             + " and u."
             + SafeUserNameColumn
             + " LIKE @1)",
             new object[] { roleName, usernameToMatch }
             )
                                    .ToList();
         string[] users = new string[userNames.Count];
         for (int i = 0; i < userNames.Count; i++)
         {
             users[i] = (string)userNames[i][0];
         }
         return(users);
     }
 }
Пример #2
0
        /// <summary>
        /// Gets an array of user names in a role where the user name contains the specified user name to match.
        /// </summary>
        /// <remarks>Inherited from RoleProvider ==> Forwarded to previous provider if this provider hasn't been initialized</remarks>
        /// <param name="roleName">The role to search in.</param>
        /// <param name="usernameToMatch">The user name to search for.</param>
        /// <returns>A string array containing the names of all the users where the user name matches <paramref name="usernameToMatch" /> and the user is a member of the specified role.</returns>
        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            if (!InitializeCalled)
            {
                return(PreviousProvider.FindUsersInRole(roleName, usernameToMatch));
            }
            using (var db = NewMySqlSecurityDbContext)
            {
                // REVIEW: Is there any way to directly get out a string[]?
                var users = db.UsersInRoles.Where(x => x.Role.RoleName == roleName && x.UserProfile.UserName.Contains(usernameToMatch))
                            .Select(x => x.UserProfile.UserName)
                            .ToArray();

                return(users);
            }
        }