/// <summary> /// Adds a new role to the data source for the configured applicationName. /// </summary> /// <param name="roleName">The name of the role to create.</param> public override void CreateRole(string roleName) { // Validate role name if (roleName.Contains(",")) { throw new ArgumentException("Role names cannot contain commas."); } if (RoleExists(roleName)) { throw new ProviderException("Role name already exists."); } try { using (InventoryManagementEntities context = new InventoryManagementEntities()) { aspnet_Applications application = ProviderUtils.EnsureApplication(ApplicationName, context); // Create new role aspnet_Roles newRole = new aspnet_Roles { RoleId = Guid.NewGuid(), RoleName = roleName, LoweredRoleName = roleName.ToLower(), ApplicationId = application.ApplicationId }; context.aspnet_Roles.Add(newRole); context.SaveChanges(); } } catch (Exception ex) { if (WriteExceptionsToEventLog) { WriteToEventLog(ex, "CreateRole"); } else { throw; } } }