UpdateEditor on UserPart

Topics: Core, Customizing Orchard, Writing modules
Apr 21, 2012 at 12:52 AM

I have created a new part that is attached with the UserPart to a ContentType. When calling UpdateEditor on the new part, the UserRolesPart driver is being called and removing the user's roles every time I call UpdateEditor on the new ContentPart. I would like to use UpdateEditor so others can add their own types or fields but I can't figure out how to keep the role(s) from being removed from my user on update. I'm pretty sure this happens because UserRolesPart is attached to UserPart and Orchard always expects roles to come along for the ride on update. However, I don't want the UserRolesDriver to get called at all on my custom page. Is there anyway I can prevent that driver from being called on the UpdateEditor for this controller action?

Apr 23, 2012 at 3:16 AM
Edited Apr 23, 2012 at 3:19 AM

I found a solution that worked for me. After looking through the UserRolesPartDriver.Editor code I noticed that within this method, the adding and removing roles process occurs if the 

(updater.TryUpdateModel(model, Prefix, null, null))

returns true. So within my controller (which implements IUpdateModel), I simply implemented the TryUpdateModel method like so:

bool IUpdateModel.TryUpdateModel(TModel model, string prefix, string[] includeProperties, string[] excludeProperties)
            // Check for UserRolesViewModel and return false to prevent the UserRolesPartDriver from touching roles
            if (model.GetType() == typeof(UserRolesViewModel))
                return false;

            return TryUpdateModel(model, prefix, includeProperties, excludeProperties);