Add a Document dynamically for User Role

kuntesh thakker asked on April 29, 2015 09:49

I want to do some action when any user is edited for a role . When i update or add any roles to the user then where should i add my custom code

Recent Answers


Brenden Kehren answered on April 29, 2015 13:50

Create a custom event handler. The example shows how to catch a global event for an update to a user object. You could do the same with the user role object (or just use the user and check if they are in the role(s) you are looking for).

[CustomClassLoaderModule]
public partial class CMSModuleLoader
{
    /// <summary>
    /// Summary description for CustomClassLoaderModuleAttribute 
    /// </summary>
    private class CustomClassLoaderModuleAttribute : CMSLoaderAttribute
    {
        //private UserInfo lastUserInfo;

        /// <summary>
        /// Initializes the module
        /// </summary>
        public override void Init()
        {
            ObjectEvents.Update.SupportsCancel = true;
            ObjectEvents.Update.After += Update_After;
        }

        private void Update_After(object sender, ObjectEventArgs e)
        {
            switch (e.Object.ObjectType.ToLower())
            {
                case "cms.user":
                    UserInfo ui = (UserInfo)e.Object;

                    if (ui != null)
                    {
                        // do some work here
                    }
                    break;
            }
        }
    }
}
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.