/// <summary> Updates a specific LDAP profile. </summary> public void UpdateLdapProfile(LdapProfileDTO dto) { if (dto == null) throw new ArgumentNullException("dto"); const string sql = @" UPDATE [dbo].[LdapProfiles] SET [Name] = @name, [ServerType] = @serverType, [UseForLogin] = @useForLogin, [ServerPath] = @serverPath, [Username] = @username, [Password] = @password, [RootPath] = @rootPath, [SearchFilter] = @searchFilter, [UseSSL] = @useSSL WHERE [Id] = @id "; using (var cmd = new SqlCommand(sql)) { cmd.Parameters.AddWithValue("@name", dto.Name.AsNullableObj()); cmd.Parameters.AddWithValue("@serverType", (int)dto.ServerType); cmd.Parameters.AddWithValue("@useForLogin", dto.UseForLogin); cmd.Parameters.AddWithValue("@serverPath", dto.ServerPath.AsNullableObj()); cmd.Parameters.AddWithValue("@username", EncryptionService.EncryptString(dto.Username ?? string.Empty)); cmd.Parameters.AddWithValue("@password", EncryptionService.EncryptString(dto.Password ?? string.Empty)); cmd.Parameters.AddWithValue("@rootPath", dto.RootPath.AsNullableObj()); cmd.Parameters.AddWithValue("@searchFilter", dto.SearchFilter.AsNullableObj()); cmd.Parameters.AddWithValue("@useSSL", dto.UseSSL); cmd.Parameters.AddWithValue("@id", dto.Id); Database.Execute(cmd); } }
/// <summary> Creates new LDAP profile. </summary> public void InsertLdapProfile(LdapProfileDTO dto) { if (dto == null) throw new ArgumentNullException("dto"); const string sql = @" INSERT INTO [dbo].[LdapProfiles] ( [Name] ,[UseForLogin] ,[ServerPath] ,[Username] ,[Password] ,[RootPath] ,[UseSSL] ,[ServerType] ,[SearchFilter] ) VALUES ( @name ,@useForLogin ,@serverPath ,@username ,@password ,@rootPath ,@useSSL ,@serverType ,@searchFilter ) SELECT [Id] FROM [dbo].[LdapProfiles] WHERE [Id] = SCOPE_IDENTITY() "; using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false)) { var cn = ctx.Connection; using (var cmd = new SqlCommand(sql, cn)) { cmd.Parameters.AddWithValue("@name", dto.Name.AsNullableObj()); cmd.Parameters.AddWithValue("@serverType", (int)dto.ServerType); cmd.Parameters.AddWithValue("@useForLogin", dto.UseForLogin); cmd.Parameters.AddWithValue("@serverPath", dto.ServerPath.AsNullableObj()); cmd.Parameters.AddWithValue("@username", EncryptionService.EncryptString(dto.Username ?? string.Empty)); cmd.Parameters.AddWithValue("@password", EncryptionService.EncryptString(dto.Password ?? string.Empty)); cmd.Parameters.AddWithValue("@rootPath", dto.RootPath.AsNullableObj()); cmd.Parameters.AddWithValue("@searchFilter", dto.SearchFilter.AsNullableObj()); cmd.Parameters.AddWithValue("@useSSL", dto.UseSSL); dto.Id = (int) cmd.ExecuteScalar(); } } }