privatevoid CreateRole() { // Create new role object RoleInfo newRole = newRoleInfo(); // Set the properties newRole.DisplayName = "My new role"; newRole.RoleName = "MyNewRole"; newRole.SiteID = CMSContext.CurrentSiteID; // Save the role RoleInfoProvider.SetRoleInfo(newRole); }
The following example gets and updates a role.
privatebool GetAndUpdateRole() {
// Get the role RoleInfo updateRole = RoleInfoProvider.GetRoleInfo("MyNewRole", CMSContext.CurrentSiteID);
if (updateRole != null) { // Update the properties updateRole.DisplayName = updateRole.DisplayName.ToLower(); // Save the changes RoleInfoProvider.SetRoleInfo(updateRole); returntrue; } returnfalse; }
The following example gets and bulk updates roles.
privatebool GetAndBulkUpdateRoles() { // Prepare the parameters string where = "RoleName LIKE N'MyNewRole%'"; // Get the data DataSet roles = RoleInfoProvider.GetRoles(where, null); if (!DataHelper.DataSourceIsEmpty(roles)) { // Loop through the individual items foreach (DataRow roleDr in roles.Tables[0].Rows) { // Create object from DataRow RoleInfo modifyRole = newRoleInfo(roleDr); // Update the properties modifyRole.DisplayName = modifyRole.DisplayName.ToUpper(); // Save the changes RoleInfoProvider.SetRoleInfo(modifyRole); } returntrue; } returnfalse; }
The following example deletes a role.
privatebool DeleteRole() {
// Get the role RoleInfo deleteRole = RoleInfoProvider.GetRoleInfo("MyNewRole", CMSContext.CurrentSiteID);
// Delete the role RoleInfoProvider.DeleteRoleInfo(deleteRole); return (deleteRole != null); }