29-11-2023
This commit is contained in:
@@ -14,6 +14,8 @@ Public MustInherit Class BaseController
|
||||
Public UserModel As UserModel
|
||||
Public EmailModel As EmailModel
|
||||
|
||||
Public ActionService As ActionService
|
||||
|
||||
Public ReadOnly Property Database As MSSQLServer
|
||||
Public ReadOnly Property State As State
|
||||
|
||||
@@ -22,6 +24,7 @@ Public MustInherit Class BaseController
|
||||
State = pState
|
||||
Database = pState.Database
|
||||
InitializeModels(pState)
|
||||
ActionService = New ActionService(pState)
|
||||
End Sub
|
||||
|
||||
Private Sub InitializeModels(pState As State)
|
||||
@@ -39,6 +42,15 @@ Public MustInherit Class BaseController
|
||||
Return True
|
||||
End If
|
||||
|
||||
Return ActionService.DeleteEnvelope(pEnvelope)
|
||||
|
||||
End Function
|
||||
|
||||
Public Function DeleteEnvelope_Old(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()
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -4,6 +4,7 @@ Imports DevExpress.Utils.Svg
|
||||
Imports DevExpress.XtraEditors
|
||||
Imports DevExpress.XtraGrid
|
||||
Imports DevExpress.XtraGrid.Views.Grid
|
||||
Imports DevExpress.XtraPrinting.Native
|
||||
Imports DevExpress.XtraSplashScreen
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports EnvelopeGenerator.Common
|
||||
@@ -70,7 +71,7 @@ Partial Public Class frmEnvelopeEditor
|
||||
End If
|
||||
Next
|
||||
|
||||
If Envelope.Status = Constants.EnvelopeStatus.Sent Then
|
||||
If Envelope.Status = Constants.EnvelopeStatus.EnvelopeSent Then
|
||||
' TODO - Nach Testen
|
||||
' SetFormReadonly()
|
||||
End If
|
||||
@@ -95,10 +96,6 @@ Partial Public Class frmEnvelopeEditor
|
||||
ViewDocuments.OptionsBehavior.ReadOnly = True
|
||||
End Sub
|
||||
|
||||
Private Sub frmEnvelopeEditor_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
|
||||
Controller.CleanupEnvelope()
|
||||
End Sub
|
||||
|
||||
Private Sub btnDeleteFile_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnDeleteFile.ItemClick
|
||||
If ViewDocuments.GetSelectedRows().Count > 0 Then
|
||||
Dim oDocument As EnvelopeDocument = DirectCast(ViewDocuments.GetFocusedRow(), EnvelopeDocument)
|
||||
@@ -133,7 +130,7 @@ Partial Public Class frmEnvelopeEditor
|
||||
Where(Function(d) d.Filename = oDocument.Filename).
|
||||
SingleOrDefault(),
|
||||
.GDPictureKey = oGDPictureKey,
|
||||
.Receivers = Receivers.ToList,
|
||||
.Receivers = Controller.Envelope.Receivers.ToList,
|
||||
.State = State
|
||||
}
|
||||
oForm.ShowDialog()
|
||||
@@ -174,6 +171,37 @@ Partial Public Class frmEnvelopeEditor
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Private Function ValidateEnvelope() As List(Of String)
|
||||
Dim oSubject = GetEditValueFromTextControl(txtSubject)
|
||||
Dim oMessage = GetEditValueFromTextControl(txtMessage)
|
||||
|
||||
Dim oErrors As New List(Of String)
|
||||
|
||||
If String.IsNullOrWhiteSpace(oSubject) Then
|
||||
oErrors.Add(Resources.Envelope.Missing_Subject)
|
||||
End If
|
||||
|
||||
If String.IsNullOrWhiteSpace(oMessage) Then
|
||||
oErrors.Add(Resources.Envelope.Missing_Message)
|
||||
End If
|
||||
|
||||
If Documents.Count = 0 Then
|
||||
oErrors.Add(Resources.Envelope.Missing_Documents)
|
||||
End If
|
||||
|
||||
If Receivers.Count = 0 Then
|
||||
oErrors.Add(Resources.Envelope.Missing_Receivers)
|
||||
End If
|
||||
|
||||
For Each Receiver In Receivers
|
||||
If Helpers.IsValidEmailAddress(Receiver.Email) = False Then
|
||||
oErrors.Add(String.Format(Resources.Envelope.Invalid_Email_Address, Receiver.Name))
|
||||
End If
|
||||
Next
|
||||
|
||||
Return oErrors
|
||||
End Function
|
||||
|
||||
Private Function SaveEnvelope(pWithValidation As Boolean) As Boolean
|
||||
Dim oSubject = GetEditValueFromTextControl(txtSubject)
|
||||
Dim oMessage = GetEditValueFromTextControl(txtMessage)
|
||||
@@ -181,20 +209,25 @@ Partial Public Class frmEnvelopeEditor
|
||||
' Ensure all receivers are saved
|
||||
ViewReceivers.CloseEditor()
|
||||
|
||||
Dim oEnvelope = Controller.Envelope
|
||||
oEnvelope.Subject = oSubject
|
||||
oEnvelope.Message = oMessage
|
||||
oEnvelope.Documents = Documents.ToList
|
||||
|
||||
If pWithValidation = True Then
|
||||
Dim oErrors = oEnvelope.Validate()
|
||||
Dim oErrors = ValidateEnvelope()
|
||||
If oErrors.Any Then
|
||||
ShowValidationErrors(Resources.Envelope.Errors_when_saving_the_envelope, oErrors)
|
||||
Return False
|
||||
End If
|
||||
End If
|
||||
|
||||
If Controller.CreateEnvelopeReceivers(Receivers.ToList) = False Then
|
||||
Dim oEnvelope = Controller.Envelope
|
||||
oEnvelope.Subject = oSubject
|
||||
oEnvelope.Message = oMessage
|
||||
oEnvelope.Documents = Documents.ToList
|
||||
|
||||
|
||||
'oEnvelope.Receivers = Receivers.ToList
|
||||
|
||||
|
||||
|
||||
If Controller.SaveReceivers(oEnvelope, Receivers.ToList) = False Then
|
||||
MsgBox(Resources.Envelope.Error_when_saving_the_recipients, MsgBoxStyle.Critical, Text)
|
||||
Return False
|
||||
End If
|
||||
@@ -249,7 +282,7 @@ Partial Public Class frmEnvelopeEditor
|
||||
End Sub
|
||||
|
||||
Private Sub btnSendEnvelope_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnSendEnvelope.ItemClick
|
||||
If Controller.Envelope.Status = Constants.EnvelopeStatus.Sent Then
|
||||
If Controller.Envelope.Status = Constants.EnvelopeStatus.EnvelopeSent Then
|
||||
MsgBox(Resources.Envelope.Envelope_already_sent, MsgBoxStyle.Information, Text)
|
||||
Exit Sub
|
||||
End If
|
||||
@@ -258,7 +291,9 @@ Partial Public Class frmEnvelopeEditor
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Dim oErrors = Controller.ValidateEnvelopeForSending()
|
||||
Dim oErrors = ValidateEnvelope()
|
||||
oErrors = Controller.ValidateEnvelopeForSending(oErrors)
|
||||
|
||||
If oErrors.Any() Then
|
||||
ShowValidationErrors(Resources.Envelope.Error_sending_the_envelope, oErrors)
|
||||
Exit Sub
|
||||
|
||||
@@ -298,10 +298,10 @@
|
||||
<value>1088, 158</value>
|
||||
</data>
|
||||
<data name="RibbonStatusBar.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>0, 657</value>
|
||||
<value>0, 659</value>
|
||||
</data>
|
||||
<data name="RibbonStatusBar.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>1088, 24</value>
|
||||
<value>1088, 22</value>
|
||||
</data>
|
||||
<data name=">>RibbonStatusBar.Name" xml:space="preserve">
|
||||
<value>RibbonStatusBar</value>
|
||||
@@ -328,7 +328,7 @@
|
||||
<value>2</value>
|
||||
</data>
|
||||
<data name="GridEnvelopes.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>1086, 294</value>
|
||||
<value>1086, 415</value>
|
||||
</data>
|
||||
<data name="GridEnvelopes.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>2</value>
|
||||
@@ -346,7 +346,7 @@
|
||||
<value>0</value>
|
||||
</data>
|
||||
<data name="XtraTabPage1.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>1086, 294</value>
|
||||
<value>1086, 415</value>
|
||||
</data>
|
||||
<data name="XtraTabPage1.Text" xml:space="preserve">
|
||||
<value>Offene Umschläge</value>
|
||||
@@ -436,7 +436,7 @@
|
||||
<value>112</value>
|
||||
</data>
|
||||
<data name="GridCompleted.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>1086, 413</value>
|
||||
<value>1086, 415</value>
|
||||
</data>
|
||||
<data name="GridCompleted.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>3</value>
|
||||
@@ -454,7 +454,7 @@
|
||||
<value>0</value>
|
||||
</data>
|
||||
<data name="XtraTabPage2.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>1086, 413</value>
|
||||
<value>1086, 415</value>
|
||||
</data>
|
||||
<data name="XtraTabPage2.Text" xml:space="preserve">
|
||||
<value>Abgeschlossene Umschläge</value>
|
||||
@@ -514,7 +514,7 @@
|
||||
<value>1</value>
|
||||
</data>
|
||||
<data name="SplitContainerControl1.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>1088, 499</value>
|
||||
<value>1088, 501</value>
|
||||
</data>
|
||||
<data name="SplitContainerControl1.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>5</value>
|
||||
|
||||
Reference in New Issue
Block a user