Dear Dynamicweb,
What is best practise for getting specific users from the api when the methods GetUsersBySql and and GetUsers(CommandBuilder) are obsolete?
Best regards,
Anders
Dear Dynamicweb,
What is best practise for getting specific users from the api when the methods GetUsersBySql and and GetUsers(CommandBuilder) are obsolete?
Best regards,
Anders
Hi Anders,
We typically use the methods on this Dynamicweb.Security.UserManagement.User class.
Dear Kevin,
Thanks for quick answer here. The case is that we need users with a certain customnumber and a specific value in a custom field on the user.
And I cannot see how this is done by the current api?
Best regards,
Anders
You cannot - only by using the obsolete API - it will stick around until DW10 though...
For such scenarios we've used a User Repository with index, queries etc. if you don't need the user object themselves.
Hi Kevin,
I have tried this solution myself but I am encountering some errors every time I add a new user and try to read the users immediately after.
Have you seen something similar? Maybe you have found a solution to it?
Thank you,
Adrian
You could create your own safe SQL query to fetch the users from the database and then use Fill to populate them:
private static UserCollection GetUsersByCustomerNumber(string customerNumber) { var users = new UserCollection(); var sqlCommandText = "SELECT * FROM AccessUser WHERE AccessUserCustomerNumber = {0} AND AccessUser_IsCompany = 1"; var commandBuilder = new CommandBuilder(); commandBuilder.Add(sqlCommandText, customerNumber); using (var dataReader = Database.CreateDataReader(commandBuilder)) { while (dataReader.Read()) { var user = new User(); user.Fill(dataReader); users.Add(user); } } return users; }
This only loads the basic user data, so not sure if this gives you exactly what you need (for example, I assume this won't load addresses). If that's a concern, you could do a double query: fetch user IDs with a custom query and then use the API to fetch those users by their ID.
Imar
You must be logged in to post in the forum