Came right with this:
AddRole method:
public bool addRoleToUser(UserInfo user, string roleName, DateTime expiry)
{
bool rc = false;
RoleInfo newRole = roleController.GetRoleByName(user.PortalID, roleName);
if (newRole != null && user != null)
{
rc = user.IsInRole(roleName);
roleController.AddUserRole(user.PortalID, user.UserID, newRole.RoleID, DateTime.MinValue, expiry);
user = UserController.GetUserById(user.PortalID, user.UserID);
rc = user.IsInRole(roleName);
}
return rc;
}
Create user and add to role:
private void ApproveFor(WholesaleClient client)
{
client.IsVerified = true;
var userInfo = GenerateUserInfo(client);
var createStatus = membershipProvider.CreateUser(ref userInfo);
if (createStatus == UserCreateStatus.InvalidPassword)
throw new Exception("Invalid password");
//save back to table with IsVerified set
if (createStatus == UserCreateStatus.Success)
{
var roleName = "Wholesale Client";
addRoleToUser(userInfo, roleName, DateTime.MaxValue);
clientRepository.Update(client);
return;
}
throw new Exception("Error occurred");
}