/// <summary> /// Creates the role. /// </summary> /// <param name="rolename">The rolename.</param> public override void CreateRole(string rolename) { if (rolename.IndexOf(',') != -1) { throw new ArgumentException(Resources.InvalidCharactersInUserName); } if (RoleExists(rolename)) { throw new ProviderException(Resources.RoleNameAlreadyExists); } using (MySqlConnection connection = new MySqlConnection(connectionString)) { try { connection.Open(); // create or fetch a new application id SchemaManager.CreateOrFetchApplicationId(applicationName, ref applicationId, base.Description, connection); MySqlCommand cmd = new MySqlCommand( @"INSERT INTO my_aspnet_Roles Values(NULL, @appId, @name)", connection); cmd.Parameters.AddWithValue("@appId", applicationId); cmd.Parameters.AddWithValue("@name", rolename); cmd.ExecuteNonQuery(); } catch (MySqlException e) { if (WriteExceptionsToEventLog) { WriteToEventLog(e, "CreateRole"); } throw; } } }
/// <summary> /// Sets the values of the specified group of property settings. /// </summary> /// <param name="context">A <see cref="T:System.Configuration.SettingsContext"/> describing the current application usage.</param> /// <param name="collection">A <see cref="T:System.Configuration.SettingsPropertyValueCollection"/> representing the group of property settings to set.</param> public override void SetPropertyValues( SettingsContext context, SettingsPropertyValueCollection collection) { bool isAuthenticated = (bool)context["IsAuthenticated"]; string username = (string)context["UserName"]; if (String.IsNullOrEmpty(username)) { return; } if (collection.Count < 1) { return; } string index = String.Empty; string stringData = String.Empty; byte[] binaryData = null; int count = EncodeProfileData(collection, isAuthenticated, ref index, ref stringData, ref binaryData); if (count < 1) { return; } // save the encoded profile data to the database try { using (TransactionScope ts = new TransactionScope()) { using (MySqlConnection connection = new MySqlConnection(connectionString)) { connection.Open(); // create or fetch a new application id SchemaManager.CreateOrFetchApplicationId(applicationName, ref applicationId, base.Description, connection); // either create a new user or fetch the existing user id int userId = SchemaManager.CreateOrFetchUserId(connection, username, applicationId, isAuthenticated); MySqlCommand cmd = new MySqlCommand( @"INSERT INTO my_aspnet_Profiles VALUES (@userId, @index, @stringData, @binaryData, NULL) ON DUPLICATE KEY UPDATE valueindex=VALUES(valueindex), stringdata=VALUES(stringdata), binarydata=VALUES(binarydata)", connection); cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@userId", userId); cmd.Parameters.AddWithValue("@index", index); cmd.Parameters.AddWithValue("@stringData", stringData); cmd.Parameters.AddWithValue("@binaryData", binaryData); count = cmd.ExecuteNonQuery(); if (count == 0) { throw new Exception(Resources.ProfileUpdateFailed); } ts.Complete(); } } } catch (Exception ex) { throw new ProviderException(Resources.ProfileUpdateFailed, ex); } }