Update User Roles Valid To Date

Kashif Akram asked on December 2, 2021 01:47

hi there, I've been trying to update the user's existing role 's validity, I am able to get role and set the validity but for some reason it's not being saved.

                   if (newUserRole != null)
                {
                    newUserRole.ValidTo = newValidity;
                    UserRoleInfoProvider.SetUserRoleInfo(newUserRole);
                }

I have tried newUserRole.Update() as well, any help would be much appreciated.

Correct Answer

vasu yerramsetti answered on December 2, 2021 05:27

Try this -

DateTime dt = ValidationHelper.GetDateTime(eventArgument, DateTimeHelper.ZERO_TIME);
                UserRoleInfo uri = UserRoleInfoProvider.GetUserRoleInfo(mUserId, id);
                if (uri != null)
                {
                    uri.ValidTo = dt;
                    UserRoleInfoProvider.SetUserRoleInfo(uri);
                    }

You can find detailed code for Assign role to user with validTo from the following page on Source code.

CMS/CMSModules/Membership/Pages/Users/User_Edit_Roles.aspx

1 votesVote for this answer Unmark Correct answer

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