TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Krishnan Suba
1.7k
82
15k
How to assign the multiple specific roles in single user?
Sep 3 2019 3:51 AM
In kentico 10 we using bulk user upload from excel, the field name is Username, Email, fname, lname, Role1, Role2 and Role3.
The user will be insert working fine.
But, Roles are not insert. If I debug the code, the cursor not going to inside the if condition.
private UserInfo CreateUser(UserDto userDto, SiteInfo site){
var newUser = new UserInfo{
UserName = userDto.UserName,
UserEnabled = true,
FirstName = userDto.FirstName,
LastName = userDto.LastName,
FullName = userDto.FirstName + " " + userDto.LastName,
Email = userDto.Email,
SiteIndependentPrivilegeLevel = CMS.Base.UserPrivilegeLevelEnum.None};
var newUserSettings = newUser.UserSettings ?? new UserSettingsInfo();
UserInfoProvider.SetPassword(newUser, userDto.UserPassword);
newUserSettings.UserPhone = userDto.PhoneNumber;
// var role = new RoleProvider().GetAllRoles(site.SiteID);
// .FirstOrDefault(r => r.Description == userDto.Role1);
UserInfoProvider.SetUserInfo(newUser);
UserInfoProvider.AddUserToSite(newUser.UserName, site.SiteName);
// var rolelist = userDto.Role1 ?? $"{userDto.Role2} {userDto.Role3}";
var rolelist = new[] { $"{userDto.Role1}", userDto.Role2, userDto.Role3}
.Where(af => !string.IsNullOrWhiteSpace(af));
foreach (var u in rolelist){
List<string> userRoles = new List<string> { userDto.Role1, userDto.Role2, userDto.Role3 };
foreach (string r in userRoles){
var roles = RoleInfoProvider.GetRoles().WhereEquals("LOWER(RoleDescription)", r.ToLower()).FirstOrDefault();
if (userRoles != null){
UserInfoProvider.AddUserToRole(newUser.UserID, roles.RoleID);
}}}
return newUser;}
Reply
Answers (
1
)
How to play youtube video auto on page load asp.net webform?
Nested for loops for N times in C#.