Roles in DNN are not a part of UserInfo they are managed separately by the roles controller entity.
For example - to add a user to a new role and set and expiry date of 31 January 2012:
DotNetNuke.Security.Roles.RoleController rc = new DotNetNuke.Security.Roles.RoleController();
DotNetNuke.Security.Roles.RoleInfo someRole = rc.GetRoleByName(PortalId, "Some Role");
DateTime expiryDate = new DateTime(2012,1,31)'
rc.AddUserRole(thisPortalId, someuser.UserId, someRole.RoleID, expiryDate );Ne
Next there is a way to have the system automatically update a role to a new date if the parent role has a billing period defined.
If for example the role Some Role has a period of 1 Month defined in Admin - the following would cause the expiry date of a userinfo someuser to be incremented by a1 Month.
DotNetNuke.Security.Roles.RoleController rc = new DotNetNuke.Security.Roles.RoleController();
DotNetNuke.Security.Roles.RoleInfo someRole = rc.GetRoleByName(PortalId, "Some Role");
rc.UpdateUserRole(PortalID, someuser.UserId , someRole.RoleID );
Alternatively, if you want to be able to control the exact date the expiry date is updated to without having to rely on the period defined for the role - I tend to perform 2 steps - delete the current role and add a new one.
DotNetNuke.Security.Roles.RoleInfo someRole = rc.GetRoleByName(PortalId, "Some Role");
rc.DeleteUserRole(PortalId, someuser.UserId , someRole.RoleID);
DateTime expiryDate = new DateTime(2012,1,31)'
rc.AddUserRole(thisPortalId, someuser.UserId, someRole.RoleID, expiryDate );
NOTE - you can also do this in one step - bu JUST calling the rc.AddUser without calling the rc.DeleteUser - cant recall why we used to do the delete and add - think it was about event reporting. If you call rc.AddUser and event already exists - it will just update the expiry date.
I would also suggest you wrap the Deleteuser / Adduser calls in try/catch since if the role does not exist or already exists you may get an exception error.
One last thing also - make sure once you finish any role manipulation that you clear the system caches.
DotNetNuke.Security.PortalSecurity.ClearRoles();
DotNetNuke.Common.Utilities.DataCache.ClearUserCache(PortalId, someUser.Username);
Westa
,