Krishnan Suba

Krishnan Suba

  • 1.7k
  • 82
  • 15k

How to assign the multiple roles in single user?

Aug 29 2019 9:57 AM
we using bulk user upload using excel, the field name is Username, Email, fname, lname, Role1, Role2 and Role3.
The username, email,fname, lname saving the data in db its working fine.
How to assign the 3 roles in single user.
I using below code
var newUser = new UserInfo{
UserName = userDto.UserName,
FirstName = userDto.FirstName,
LastName = userDto.LastName,
Email = userDto.Email,
SiteIndependentPrivilegeLevel = CMS.Base.UserPrivilegeLevelEnum.None };
var newUserSettings = newUser.UserSettings ?? new UserSettingsInfo();
UserInfoProvider.SetUserInfo(newUser);
UserInfoProvider.AddUserToSite(newUser.UserName, site.SiteName);
var role = new RoleProvider().GetAllRoles(site.SiteID)
.FirstOrDefault(r => r.Description == userDto.Role1);
// .(r => r.Description == userDto.Role1, userDto.Role2, userDto.Role3);
UserInfoProvider.AddUserToRole(newUser.UserID, role.ID);
return newUser;

Answers (2)