16-08-23
This commit is contained in:
101
EnvelopeGenerator.Form/Controllers/BaseController.vb
Normal file
101
EnvelopeGenerator.Form/Controllers/BaseController.vb
Normal file
@@ -0,0 +1,101 @@
|
||||
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 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)
|
||||
End Sub
|
||||
|
||||
Public Function DeleteEnvelope(pEnvelope As Envelope) As Boolean
|
||||
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
|
||||
@@ -1,60 +1,28 @@
|
||||
Imports System.Data.Common
|
||||
Imports System.Data.SqlClient
|
||||
Imports System.Data.SqlClient
|
||||
Imports System.IO
|
||||
Imports DigitalData.Modules.Base
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports EnvelopeGenerator.Common
|
||||
Imports EnvelopeGenerator.Common.Constants
|
||||
|
||||
Public Class EnvelopeEditorController
|
||||
Inherits BaseClass
|
||||
|
||||
Private ReadOnly Database As MSSQLServer
|
||||
Private ReadOnly State As State = Nothing
|
||||
|
||||
Private EnvelopeModel As EnvelopeModel
|
||||
Private DocumentModel As DocumentModel
|
||||
Private ReceiverModel As ReceiverModel
|
||||
Private ElementModel As ElementModel
|
||||
Private HistoryModel As HistoryModel
|
||||
Private UserModel As UserModel
|
||||
Inherits BaseController
|
||||
|
||||
Public ReadOnly Envelope As Envelope = Nothing
|
||||
|
||||
Public Sub New(pState As State)
|
||||
MyBase.New(pState.LogConfig)
|
||||
|
||||
Database = pState.Database
|
||||
State = pState
|
||||
|
||||
InitializeModels(pState)
|
||||
MyBase.New(pState)
|
||||
|
||||
Envelope = CreateEnvelope()
|
||||
End Sub
|
||||
|
||||
Public Sub New(pState As State, pEnvelope As Envelope)
|
||||
MyBase.New(pState.LogConfig)
|
||||
|
||||
Database = pState.Database
|
||||
State = pState
|
||||
|
||||
InitializeModels(pState)
|
||||
MyBase.New(pState)
|
||||
|
||||
Envelope = pEnvelope
|
||||
Envelope.Documents = DocumentModel.List(pEnvelope.Id)
|
||||
Envelope.Receivers = ReceiverModel.ListEnvelopeReceivers(pEnvelope.Id)
|
||||
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)
|
||||
End Sub
|
||||
|
||||
#Region "Public"
|
||||
Public Function CreateEnvelope() As Envelope
|
||||
Dim oEnvelope As New Envelope() With {
|
||||
@@ -114,9 +82,7 @@ Public Class EnvelopeEditorController
|
||||
|
||||
Public Function CleanupEnvelope() As Boolean
|
||||
If Envelope.Status = Common.Constants.EnvelopeStatus.Created Then
|
||||
'TODO: Delete Documents and Receivers and elements
|
||||
Return EnvelopeModel.Delete(Envelope)
|
||||
|
||||
Return DeleteEnvelope(Envelope)
|
||||
Else
|
||||
Return True
|
||||
End If
|
||||
@@ -141,14 +107,17 @@ Public Class EnvelopeEditorController
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function DeleteDocument(pDocument As EnvelopeDocument) As Boolean
|
||||
Dim oSql = "DELETE FROM [dbo].[TBSIG_ENVELOPE_DOCUMENT] WHERE FILENAME = @FILENAME AND ENVELOPE_ID = @ENVELOPE_ID"
|
||||
Dim oCommand As New SqlCommand(oSql)
|
||||
oCommand.Parameters.Add("FILENAME", SqlDbType.NVarChar).Value = pDocument.Filename
|
||||
oCommand.Parameters.Add("ENVELOPE_ID", SqlDbType.Int).Value = Envelope.Id
|
||||
'TODO: delete document file, from temp and from documentpath
|
||||
Public Overloads Function DeleteDocument(pDocument As EnvelopeDocument) As Boolean
|
||||
Dim oConnection As SqlConnection = Database.GetConnection
|
||||
Dim oTransaction As SqlTransaction = oConnection.BeginTransaction
|
||||
|
||||
Return Database.ExecuteNonQuery(oCommand)
|
||||
If DeleteDocument(pDocument, oTransaction) = True Then
|
||||
oTransaction.Commit()
|
||||
Return True
|
||||
Else
|
||||
oTransaction.Rollback()
|
||||
Return False
|
||||
End If
|
||||
End Function
|
||||
|
||||
Public Function SaveEnvelopeDocumentsToFilesystem(pEnvelope As Envelope) As Boolean
|
||||
@@ -206,28 +175,21 @@ Public Class EnvelopeEditorController
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function CreateEnvelopeReceivers(pReceivers As List(Of EnvelopeReceiver)) As Boolean
|
||||
Dim oExistingReceivers As List(Of EnvelopeReceiver) = ReceiverModel.ListReceivers(pReceivers)
|
||||
Public Function CreateEnvelopeReceivers(pCurrentReceivers As List(Of EnvelopeReceiver)) As Boolean
|
||||
Dim oExistingReceivers As List(Of EnvelopeReceiver) = ReceiverModel.ListReceivers(pCurrentReceivers)
|
||||
Dim oExistingAddresses = oExistingReceivers.Select(Function(r) r.Email)
|
||||
|
||||
Dim oNewReceivers = pReceivers.
|
||||
Dim oNewReceivers = pCurrentReceivers.
|
||||
Where(Function(r) Not oExistingAddresses.Contains(r.Email)).ToList()
|
||||
|
||||
Dim oOldReceivers = pReceivers.
|
||||
Where(Function(r) oExistingAddresses.Contains(r.Email)).ToList()
|
||||
|
||||
For Each oReceiver In oOldReceivers
|
||||
oReceiver.Id = oExistingReceivers.
|
||||
Where(Function(r) r.Email = oReceiver.Email).
|
||||
Select(Function(r) r.Id).
|
||||
FirstOrDefault()
|
||||
For Each oReceiver In oNewReceivers
|
||||
oReceiver.Id = 0
|
||||
Next
|
||||
|
||||
Dim oConnection = Database.GetConnection()
|
||||
Dim oTransaction = oConnection.BeginTransaction()
|
||||
|
||||
Try
|
||||
|
||||
If InsertReceivers(oNewReceivers, oTransaction) = False Then
|
||||
Throw New ApplicationException("Could not insert receivers!")
|
||||
End If
|
||||
@@ -261,16 +223,35 @@ Public Class EnvelopeEditorController
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function DeleteReceiver(pReceiver As EnvelopeReceiver) As Boolean
|
||||
Public Function DeleteReceiver(pReceiver As EnvelopeReceiver) As Boolean
|
||||
Dim oConnection As SqlConnection = Database.GetConnection()
|
||||
Dim oTransaction As SqlTransaction = oConnection.BeginTransaction()
|
||||
|
||||
Try
|
||||
If ReceiverModel.Delete(pReceiver.Id, Envelope.Id, oTransaction) = True Then
|
||||
Dim oResult = Envelope.Documents.
|
||||
Select(Function(d) ElementModel.DeleteElements(pReceiver.Id, d.Id, oTransaction)).
|
||||
All(Function(pResult) pResult = True)
|
||||
|
||||
If oResult = False Then
|
||||
Throw New ApplicationException("Could not delete elements!")
|
||||
End If
|
||||
Else
|
||||
Throw New ApplicationException("Could not delete receiver!")
|
||||
End If
|
||||
|
||||
oTransaction.Commit()
|
||||
Return True
|
||||
|
||||
Catch ex As Exception
|
||||
|
||||
Logger.Error(ex)
|
||||
oTransaction.Rollback()
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function ElementsExist(pDocumentId As Integer, pReceiverId As Integer) As Boolean
|
||||
Return ElementModel.ElementsExist(pDocumentId, pReceiverId)
|
||||
Public Function ElementsExist(pReceiverId As Integer) As Boolean
|
||||
Return ElementModel.ElementsExist(Envelope.Id, pReceiverId)
|
||||
End Function
|
||||
|
||||
Private Function InsertReceivers(pReceivers As List(Of EnvelopeReceiver), pTransaction As SqlTransaction) As Boolean
|
||||
|
||||
@@ -1,22 +1,18 @@
|
||||
Imports DigitalData.Modules.Base
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports EnvelopeGenerator.Common
|
||||
Imports EnvelopeGenerator.Common
|
||||
|
||||
Public Class EnvelopeListController
|
||||
Inherits BaseClass
|
||||
Private ReadOnly Database As MSSQLServer
|
||||
Private ReadOnly State As State
|
||||
Private ReadOnly EnvelopeModel As EnvelopeModel
|
||||
Inherits BaseController
|
||||
|
||||
Public Sub New(pState As State)
|
||||
MyBase.New(pState.LogConfig)
|
||||
Database = pState.Database
|
||||
State = pState
|
||||
EnvelopeModel = New EnvelopeModel(pState)
|
||||
MyBase.New(pState)
|
||||
End Sub
|
||||
|
||||
Public Function ListEnvelopes() As IEnumerable(Of Envelope)
|
||||
Return EnvelopeModel.List()
|
||||
End Function
|
||||
|
||||
Public Overloads Function DeleteEnvelope(pEnvelope As Envelope) As Boolean
|
||||
Return MyBase.DeleteEnvelope(pEnvelope)
|
||||
End Function
|
||||
|
||||
End Class
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
Imports DigitalData.Modules.Base
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports EnvelopeGenerator.Common
|
||||
Imports EnvelopeGenerator.Common
|
||||
Imports GdPicture14.Annotations
|
||||
|
||||
Public Class FieldEditorController
|
||||
Inherits BaseClass
|
||||
Inherits BaseController
|
||||
|
||||
Private ReadOnly ElementModel As ElementModel
|
||||
|
||||
Private ReadOnly Database As MSSQLServer
|
||||
Private ReadOnly Document As EnvelopeDocument
|
||||
Public Property Elements As New List(Of EnvelopeDocumentElement)
|
||||
|
||||
@@ -19,8 +14,7 @@ Public Class FieldEditorController
|
||||
End Class
|
||||
|
||||
Public Sub New(pState As State, pDocument As EnvelopeDocument)
|
||||
MyBase.New(pState.LogConfig)
|
||||
Database = pState.Database
|
||||
MyBase.New(pState)
|
||||
Document = pDocument
|
||||
|
||||
ElementModel = New ElementModel(pState)
|
||||
|
||||
Reference in New Issue
Block a user