Using a service to getAll IUser

503 Views Asked by At

In orchard 1.6 I want to get all the records in the Orchard_Users_UserPartRecord table

I can get a user by saying:

var user = _membershipService.GetUser(username);

or

 IUser userInfo = _authenticationService.GetAuthenticatedUser();

is there not a query or service of some sort that allows me to getAllUsers?...im sure there is but I cant see it so iv tried to add my own...

In Orchard.Users module in the membershipService.cs iv added:

public IEnumerable<IUser> GetAllUsers()
    {
        return _orchardServices.ContentManager.Query<UserPart, UserPartRecord>().List();
    }

tehn in the IUserService iv added:

IEnumerable<IUser> AllUsers();

and in the userService iv added:

 public IEnumerable<IUser> AllUsers()
    {
        IEnumerable<IUser> users = _membershipService.//but it doesnt allow me to select GetAllUsers, but it does allow me to seleect
            //getUser, iv used the same code only changed the query why isnt it showing?
        if (users == null)
            return null;

        return users;
    }

then where I needed to get all users I can say:

IEnumerable<IUser> allUsers = _userService.AllUsers();

I think there is a service that already does this I just dont see it. ANy ideas?

1

There are 1 best solutions below

3
On

GetAllUsers() is not available on _membershipService, because _membershipService is of the interface type IMembershipService, and not of the MembershipService class, where you added the GetAllUsers() method. To make this available, also add the method declaration for GetAllUsers() to the IMembershipService interface.

As for whether a service already exists for doing this, it doesn't seem that way. You can see that Orchard itself uses the same technique as you described above to obtain a list of users, such as in the AdminController that comes with the Orchard.Users module:

var users = Services.ContentManager
    .Query<UserPart, UserPartRecord>();