Deleting a user error
Hello everyone
I just wish to delete a user from Sitefinity and I am encountering the following error:
No data provider decorator could be found for the provider 'DynamicModule.ns.Wrapped_ValpakRoleDataProvider_ea66db37a0c74552869fecc7fd948a0b'. The method 'GetDirtyItems()' has to be overridden and implemented.
How would I go about deleting a user and/or implementing the GetDirtyItems() method?
Apologies if I'm being thick.
Hello Richard,
There is no need to apologize, we know that Sitefinity's learning curve can be steep. In general you do not need to use the GetDirtyItems method in order to delete a user. All you need to do is to get the user by a certain identifier, say Name, and then execute the Delete statement of our UserManager. The code below shows you just that:
public
static
void
DeleteUser(
string
username)
UserManager userManager = UserManager.GetManager();
UserProfileManager profileManager = UserProfileManager.GetManager();
User user = userManager.GetUsers().Where(u => u.UserName == username).SingleOrDefault();
if
(user !=
null
)
SitefinityProfile userProfile = profileManager.GetUserProfile<SitefinityProfile>(user);
if
(userProfile !=
null
)
profileManager.Delete(userProfile);
userManager.Delete(user);
profileManager.SaveChanges();
userManager.SaveChanges();
Hello Ivan
Thank you very much for this information, I'll give it a go now and see how I get on.
Rich