Imports DigitalData.Modules.Database Imports DigitalData.Modules.Base Imports EnvelopeGenerator.Common Imports System.Data.SqlClient Public MustInherit Class BaseController Inherits BaseClass Public EnvelopeModel As EnvelopeModel Public DocumentModel As DocumentModel Public ReceiverModel As ReceiverModel Public ElementModel As ElementModel Public HistoryModel As HistoryModel Public UserModel As UserModel Public EmailModel As EmailModel Public ReadOnly Property Database As MSSQLServer Public ReadOnly Property State As State Public Sub New(pState As State) MyBase.New(pState.LogConfig) State = pState Database = pState.Database InitializeModels(pState) End Sub Private Sub InitializeModels(pState As State) EnvelopeModel = New EnvelopeModel(pState) DocumentModel = New DocumentModel(pState) ReceiverModel = New ReceiverModel(pState) ElementModel = New ElementModel(pState) HistoryModel = New HistoryModel(pState) UserModel = New UserModel(pState) EmailModel = New EmailModel(pState) End Sub Public Function DeleteEnvelope(pEnvelope As Envelope) As Boolean If pEnvelope Is Nothing Then Return True End If Dim oConnection As SqlConnection = Database.GetConnection() Dim oTransaction As SqlTransaction = oConnection.BeginTransaction() Try Dim oResult = pEnvelope.Documents. Select(Function(d) DeleteDocument(d, oTransaction)). All(Function(r) r = True) If oResult = False Then Throw New ApplicationException("could not delete documents") End If Dim oResult2 = pEnvelope.Receivers. Select(Function(r) ReceiverModel.Delete(r.Id, pEnvelope.Id, oTransaction)). All(Function(r) r = True) If oResult2 = False Then Throw New ApplicationException("could not delete receivers") End If Dim oResult3 = EnvelopeModel.Delete(pEnvelope, oTransaction) If oResult3 = False Then Throw New ApplicationException("could not delete envelope") End If oTransaction.Commit() Return True Catch ex As Exception Logger.Error(ex) oTransaction.Rollback() Return False End Try End Function Public Function DeleteDocument(pDocument As EnvelopeDocument, pTransaction As SqlTransaction) As Boolean Try If DocumentModel.Delete(pDocument.Id, pTransaction) = True Then Dim oResult = ElementModel.DeleteElements(pDocument.Id, pTransaction) If oResult = False Then Throw New ApplicationException("Could not delete elements!") End If Else Throw New ApplicationException("Could not delete document!") End If Catch ex As Exception Logger.Error(ex) Return False End Try Try IO.File.Delete(pDocument.Filepath) Catch ex As Exception Logger.Error(ex) Return False End Try Return True End Function End Class