
Imports DigitalData.Modules.EDMI.API.EDMIServiceReference
Imports DigitalData.Modules.EDMI.API.Options
Imports DigitalData.Modules.Logging

Namespace Modules.IDB
    Public Class SetObjectState
        Inherits BaseMethod

        Public Sub New(pLogConfig As LogConfig, pChannel As IEDMIServiceChannel)
            MyBase.New(pLogConfig, pChannel)
        End Sub

        Public Async Function RunAsync(pObjectId As String, pState As String, Optional pOptions As SetObjectStateOptions = Nothing) As Task(Of Boolean)
            Try

                Dim oSql As String = $"EXEC PRIDB_OBJECT_SET_STATE {pObjectId}, '{pState}', '{pOptions.Username}'"
                Dim oResult = Await Channel.ExecuteNonQuery_MSSQL_IDBAsync(oSql)

                If oResult.OK Then
                    Return True
                End If

                Logger.Warn("Error while setting Object State: [{0}]", oResult.ErrorMessage)
                Return False

            Catch ex As Exception
                Logger.Error(ex)
                Return False

            End Try
        End Function
    End Class
End Namespace
