Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Database Imports DigitalData.Services.EDMIService.IDB Imports System.Data.SqlClient Namespace Methods.IDB.SetAttributeValue Public Class SetAttributeValueMethod Inherits BaseMethod Private Connection As SqlConnection Private Transaction As SqlTransaction Public Sub New(pLogConfig As LogConfig, pDatabaseIDB As MSSQLServer, pDatabaseECM As MSSQLServer, pGlobalState As GlobalState) MyBase.New(pLogConfig, pDatabaseIDB, pDatabaseECM, pGlobalState) Connection = DatabaseIDB.GetConnection() Transaction = Connection.BeginTransaction() End Sub Public Function Run(pData As SetAttributeValueRequest) As SetAttributeValueResponse Try If Helpers.TestObjectIdExists(pData.ObjectId) = False Then LogAndThrow("ObjectId does not exist!") End If Logger.Debug("Setting value of Attribute [{0}]", pData.AttributeName) Dim oResult = Helpers.SetAttributeValueWithTransaction(Connection, Transaction, pData.ObjectId, pData.AttributeName, pData.AttributeValue, pData.Language, pData.Who) If oResult = False Then LogAndThrow("Attribute value could not be set!") End If Logger.Debug("Attribute value set!") ' Finally, commit the transaction Transaction?.Commit() Return New SetAttributeValueResponse(pData.ObjectId) Catch ex As Exception Logger.Warn("Error occurred while setting attribute value!") Logger.Error(ex) Logger.Info("Rolling back transaction.") Transaction?.Rollback() Return New SetAttributeValueResponse(ex) End Try End Function End Class End Namespace