/// <summary> /// Adds the specified users to the specified roles /// </summary> public override void AddUsersToRoles(string[] usernames, string[] roleNames) { // foreach user foreach (string uname in usernames) { int userID = (from u in db.Users where u.Username == uname select u.UserID).Single(); // foreach role the user is being added to foreach (string role in roleNames) { UserRoleMapping mapping = new UserRoleMapping(); mapping.UserID = userID; mapping.UserRoleID = (from r in db.UserRoles where r.RoleName.ToLower() == role.ToLower() select r.RoleID).Single(); db.UserRoleMappings.InsertOnSubmit(mapping); } } db.SubmitChanges(); }
partial void DeleteUserRoleMapping(UserRoleMapping instance);
partial void UpdateUserRoleMapping(UserRoleMapping instance);
partial void InsertUserRoleMapping(UserRoleMapping instance);
private void detach_UserRoleMappings(UserRoleMapping entity) { this.SendPropertyChanging(); entity.User = null; }
private void attach_UserRoleMappings(UserRoleMapping entity) { this.SendPropertyChanging(); entity.UserRole = this; }