29-11-2023
This commit is contained in:
@@ -9,6 +9,7 @@ Public Class EnvelopeEditorController
|
||||
Inherits BaseController
|
||||
|
||||
Public ReadOnly Envelope As Envelope = Nothing
|
||||
Public ReadOnly EmailService As EmailService
|
||||
|
||||
Public ReadOnly Thumbnail As Thumbnail
|
||||
|
||||
@@ -17,6 +18,7 @@ Public Class EnvelopeEditorController
|
||||
|
||||
Envelope = CreateEnvelope()
|
||||
Thumbnail = New Thumbnail(pState.LogConfig)
|
||||
EmailService = New EmailService(pState)
|
||||
End Sub
|
||||
|
||||
Public Sub New(pState As State, pEnvelope As Envelope)
|
||||
@@ -27,56 +29,36 @@ Public Class EnvelopeEditorController
|
||||
Envelope.Receivers = ReceiverModel.ListEnvelopeReceivers(pEnvelope.Id).ToList()
|
||||
|
||||
Thumbnail = New Thumbnail(pState.LogConfig)
|
||||
EmailService = New EmailService(pState)
|
||||
End Sub
|
||||
|
||||
#Region "Public"
|
||||
Public Function SendEnvelope() As Boolean
|
||||
For Each receiverItem As EnvelopeReceiver In Envelope.Receivers
|
||||
|
||||
If receiverItem.Signature Is Nothing Then
|
||||
Logger.Warn("Signature for Receiver is empty. Aborting.")
|
||||
For Each receiverItem As EnvelopeReceiver In Envelope.Receivers
|
||||
If EmailService.SendInitialEmail(receiverItem.Id, Envelope.Id) = False Then
|
||||
Logger.Warn("Email could not be sent.")
|
||||
Return False
|
||||
End If
|
||||
|
||||
Dim oEmailData As New EmailData(Envelope, receiverItem) With
|
||||
{
|
||||
.SignatureLink = Helpers.GetEnvelopeURL(State.DbConfig.SignatureHost, Envelope.Uuid, receiverItem.Signature)
|
||||
}
|
||||
|
||||
Dim oTemplate As New EmailTemplate()
|
||||
oTemplate.FillDocumentReceivedEmailBody(oEmailData)
|
||||
|
||||
If EmailModel.Insert(oEmailData) = False Then
|
||||
Logger.Error("EMail data could not be inserted.")
|
||||
Dim oResult As Boolean = False
|
||||
End If
|
||||
|
||||
Next
|
||||
|
||||
|
||||
If EnvelopeModel.Send(Envelope) Then
|
||||
|
||||
Dim newHistoryEntry As New EnvelopeHistoryEntry With {
|
||||
Dim newHistoryEntry As New EnvelopeHistoryEntry With {
|
||||
.EnvelopeId = Envelope.Id,
|
||||
.ActionType = EnvelopeHistoryActionType.Sent,
|
||||
.Status = EnvelopeStatus.EnvelopeQueued,
|
||||
.UserReference = Envelope.User.Email
|
||||
}
|
||||
|
||||
If HistoryModel.Insert(newHistoryEntry) Then
|
||||
'TODO: Send email to History
|
||||
Return True
|
||||
Else
|
||||
Logger.Warn("History Entry could not be created!")
|
||||
Return False
|
||||
End If
|
||||
If HistoryModel.Insert(newHistoryEntry) Then
|
||||
Return True
|
||||
Else
|
||||
Logger.Warn("Envelope could not be updated!")
|
||||
Logger.Warn("History Entry could not be created!")
|
||||
Return False
|
||||
End If
|
||||
|
||||
End Function
|
||||
|
||||
Public Function ValidateEnvelopeForSending() As List(Of String)
|
||||
Dim oEnvelopeErrors = Envelope.Validate()
|
||||
Public Function ValidateEnvelopeForSending(pErrors As List(Of String)) As List(Of String)
|
||||
Dim oEnvelopeErrors = pErrors
|
||||
|
||||
If ElementModel.ElementsExist(Envelope.Id) = False Then
|
||||
oEnvelopeErrors.Add(Resources.Envelope.Missing_Elements)
|
||||
@@ -105,7 +87,7 @@ Public Class EnvelopeEditorController
|
||||
|
||||
Dim newHistoryEntry As New EnvelopeHistoryEntry With {
|
||||
.EnvelopeId = oEnvelope.Id,
|
||||
.ActionType = EnvelopeHistoryActionType.Created,
|
||||
.Status = EnvelopeStatus.EnvelopeCreated,
|
||||
.UserReference = oEnvelope.User.Email
|
||||
}
|
||||
|
||||
@@ -117,12 +99,38 @@ Public Class EnvelopeEditorController
|
||||
End If
|
||||
End Function
|
||||
|
||||
Public Function SaveReceivers(pEnvelope As Envelope, pReceiversFromGrid As List(Of EnvelopeReceiver)) As Boolean
|
||||
Dim oExistingReceivers As List(Of EnvelopeReceiver) = ReceiverModel.ListReceivers(pReceiversFromGrid).ToList()
|
||||
Dim oExistingAddresses = oExistingReceivers.Select(Function(r) r.Email)
|
||||
Dim oNewReceivers = pReceiversFromGrid.Where(Function(r) Not oExistingAddresses.Contains(r.Email)).ToList()
|
||||
|
||||
If CreateNewReceivers(oNewReceivers) = False Then
|
||||
Return False
|
||||
End If
|
||||
|
||||
Dim oAllReceivers As List(Of EnvelopeReceiver) = ReceiverModel.ListReceivers(pReceiversFromGrid).ToList()
|
||||
|
||||
pEnvelope.Receivers.Clear()
|
||||
|
||||
For Each oReceiver In pReceiversFromGrid
|
||||
Dim oDbReceiver = oAllReceivers.Where(Function(r) r.Email = oReceiver.Email).SingleOrDefault()
|
||||
If oDbReceiver IsNot Nothing Then
|
||||
oReceiver.Id = oDbReceiver.Id
|
||||
oReceiver.Signature = oDbReceiver.Signature
|
||||
End If
|
||||
|
||||
pEnvelope.Receivers.Add(oReceiver)
|
||||
Next
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Function SaveEnvelope() As Boolean
|
||||
Dim oConnection = Database.GetConnection()
|
||||
Dim oTransaction = oConnection.BeginTransaction(IsolationLevel.ReadUncommitted)
|
||||
|
||||
Try
|
||||
Envelope.Status = EnvelopeStatus.Saved
|
||||
Envelope.Status = EnvelopeStatus.EnvelopeSaved
|
||||
|
||||
If SaveEnvelopeDocumentsToFilesystem(Envelope) = False Then
|
||||
Throw New ApplicationException
|
||||
@@ -152,18 +160,6 @@ Public Class EnvelopeEditorController
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function CleanupEnvelope() As Boolean
|
||||
If Envelope Is Nothing Then
|
||||
Return True
|
||||
End If
|
||||
|
||||
If Envelope.Status = Common.Constants.EnvelopeStatus.Created Then
|
||||
Return DeleteEnvelope(Envelope)
|
||||
Else
|
||||
Return True
|
||||
End If
|
||||
End Function
|
||||
|
||||
Public Function CreateDocument(pDocumentFilePath As String) As EnvelopeDocument
|
||||
Try
|
||||
Dim oFileInfo = New FileInfo(pDocumentFilePath)
|
||||
@@ -270,15 +266,8 @@ Public Class EnvelopeEditorController
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function CreateEnvelopeReceivers(pCurrentReceivers As List(Of EnvelopeReceiver)) As Boolean
|
||||
Dim oExistingReceivers As List(Of EnvelopeReceiver) = ReceiverModel.ListReceivers(pCurrentReceivers).ToList()
|
||||
Dim oExistingAddresses = oExistingReceivers.Select(Function(r) r.Email)
|
||||
|
||||
' Neue Empfänger
|
||||
Dim oNewReceivers = pCurrentReceivers.
|
||||
Where(Function(r) Not oExistingAddresses.Contains(r.Email)).ToList()
|
||||
|
||||
If oNewReceivers.Count = 0 Then
|
||||
Public Function CreateNewReceivers(pNewReceivers As List(Of EnvelopeReceiver)) As Boolean
|
||||
If pNewReceivers.Count = 0 Then
|
||||
Return True
|
||||
End If
|
||||
|
||||
@@ -286,15 +275,12 @@ Public Class EnvelopeEditorController
|
||||
Dim oTransaction = oConnection.BeginTransaction()
|
||||
|
||||
Try
|
||||
If InsertReceivers(oNewReceivers, oTransaction) = False Then
|
||||
If InsertReceivers(pNewReceivers, oTransaction) = False Then
|
||||
Throw New ApplicationException("Could not insert receivers!")
|
||||
End If
|
||||
|
||||
oTransaction.Commit()
|
||||
|
||||
' Empfänger neu aus der Datenbank laden
|
||||
Envelope.Receivers = ReceiverModel.ListReceivers(pCurrentReceivers).ToList()
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
|
||||
Reference in New Issue
Block a user