Search DNN Portal User using custom Module

300 views Asked by At

Hello to all programmers out there! I am currently developing a module wherein I need to have a search for all users in my DNN portal. And I don't know what is the right way of doing so. I just have to populate a gridview with the users username and UserID with a field populated with a button. So overall. I need to have 3 fields wherein:

1st field = Username
2nd field = UserID
3rd Field = a Button(Which I already know how to include in a gridview)

I also have a textbox and a buttonSearch wherein in the textbox I will search for an existing username else, I shall throw an exception or message perhaps. So whenever there is a username existing prior to what I searched, the gridview will return with the information.

As of now I'm really puzzled here. And I only have this:

public static UserInfo GetUserByName(int portalId, string username)
{

}

And I'm not sure what to do next.

Any response would be really appreciated.

1

There are 1 answers

3
Fix It Scotty On BEST ANSWER

I updated my answer to reflect the function wrap that you originally suggested. I am using the GetUsersBasicSearch function of DotNetNuke.Entities.Users to look for a user by username. I'm not sure what you need a gridview for? If you are searching for a username, it will likely return just 1 user. Are you wanting to partially match the username and show multiple matches in a gridview?

public static UserInfo GetUserByName(int portalId, string username)
{
    var foundUsers = UserController.Instance.GetUsersBasicSearch(portalId, 0, 10, "UserID", true, "UserName", username);
    if (foundUsers.Any())
    {
        return foundUsers.FirstOrDefault();
    }
    else
    {
        return null;
    }
}