29-11-2023

This commit is contained in:
Jonathan Jenne 2023-11-29 16:15:48 +01:00
parent c964b97e55
commit 1b88a6cff7
23 changed files with 342 additions and 257 deletions

View File

@ -2,11 +2,18 @@
#Region "Status Fields"
Public Enum EnvelopeStatus
Created = 0
Saved = 1
Sent = 2
PartlySigned = 3
CompletelySigned = 4
EnvelopeCreated = 1001
EnvelopeSaved = 1002
EnvelopeQueued = 1003
EnvelopeSent = 1004
EnvelopePartlySigned = 1005
EnvelopeCompletelySigned = 1006
EnvelopeArchived = 1007
EnvelopeTransmittedDMS = 1008
EnvelopeDeleted = 1009
DocumentOpened = 2001
DocumentSigned = 2002
SignatureConfirmed = 2003
End Enum
Public Enum ElementStatus
@ -26,16 +33,16 @@
''' <summary>
''' This is a status, which is called Type because it fits with the other action fields
''' </summary>
Public Enum EnvelopeHistoryActionType
Created = 0
Saved = 1
Sent = 2
EmailSent = 3
Delivered = 4
Seen = 5
Signed = 6
Rejected = 7
End Enum
'Public Enum EnvelopeHistoryActionType
' Created = 0
' Saved = 1
' Sent = 2
' EmailSent = 3
' Delivered = 4
' Seen = 5
' Signed = 6
' Rejected = 7
'End Enum
#End Region
#Region "Type Fields"

View File

@ -4,6 +4,7 @@ Public Class EmailTemplate
Private _DocumentReceivedBodyTemplate As List(Of String)
Private _DocumentSignedBodyTemplate As List(Of String)
Private _DocumentCompletedBodyTemplate As List(Of String)
Private _DocumentDeletedBodyTemplate As List(Of String)
Private _replaceDictionary As Dictionary(Of String, String)
@ -34,6 +35,15 @@ Public Class EmailTemplate
"<NAME_SENDER>"
}
_DocumentDeletedBodyTemplate = New List(Of String) From {
"Guten Tag, <NAME_RECEIVER>",
"",
"Der User <NAME_SENDER> hat den Umschlag <DOCUMENT_TITLE> gelöscht.",
"",
"Mit freundlichen Grüßen",
"<NAME_SENDER>"
}
_DocumentCompletedBodyTemplate = New List(Of String) From {
"Guten Tag, <NAME_RECEIVER>",
"",
@ -60,6 +70,10 @@ Public Class EmailTemplate
FillEmailBody(pEmailData, _DocumentReceivedBodyTemplate)
End Sub
Public Sub FillEnvelopeDeletedEmailBody(pEmailData As EmailData)
FillEmailBody(pEmailData, _DocumentDeletedBodyTemplate)
End Sub
Public Sub FillDocumentSignedEmailBody(pEmailData As EmailData)
FillEmailBody(pEmailData, _DocumentSignedBodyTemplate)
End Sub

View File

@ -29,33 +29,7 @@
End Get
End Property
Public Function Validate() As List(Of String)
Dim oErrors As New List(Of String)
If String.IsNullOrWhiteSpace(Subject) Then
oErrors.Add(My.Resources.Envelope.Missing_Subject)
End If
If String.IsNullOrWhiteSpace(Message) Then
oErrors.Add(My.Resources.Envelope.Missing_Message)
End If
If Documents.Count = 0 Then
oErrors.Add(My.Resources.Envelope.Missing_Documents)
End If
If Receivers.Count = 0 Then
oErrors.Add(My.Resources.Envelope.Missing_Receivers)
End If
For Each Receiver In Receivers
If IsValidEmailAddress(Receiver.Email) = False Then
oErrors.Add(String.Format(My.Resources.Envelope.Invalid_Email_Address, Receiver.Name))
End If
Next
Return oErrors
End Function
Public Function ValidateReceiverDocumentData() As List(Of String)
Dim oErrors As New List(Of String)
@ -72,12 +46,5 @@
End Function
Private Function IsValidEmailAddress(pEmailAddress As String) As Boolean
Try
Dim oAddress = New System.Net.Mail.MailAddress(pEmailAddress)
Return oAddress.Address = pEmailAddress
Catch ex As Exception
Return False
End Try
End Function
End Class

View File

@ -1,6 +1,6 @@
Public Class EnvelopeHistoryEntry
Public EnvelopeId As Integer
Public UserReference As String
Public ActionType As Constants.EnvelopeHistoryActionType
Public ActionDate As Date
Public Status As Constants.EnvelopeStatus
Public ActionDate As Date = Now()
End Class

View File

@ -137,7 +137,9 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="Services\ActionService.vb" />
<Compile Include="Services\EmailService.vb" />
<Compile Include="Services\HistoryService.vb" />
<Compile Include="Strings\Email.en.Designer.vb">
<DependentUpon>Email.en.resx</DependentUpon>
<AutoGen>True</AutoGen>

View File

@ -85,4 +85,13 @@ Public Class Helpers
Return oColoredImage
End Function
Public Shared Function IsValidEmailAddress(pEmailAddress As String) As Boolean
Try
Dim oAddress = New System.Net.Mail.MailAddress(pEmailAddress)
Return oAddress.Address = pEmailAddress
Catch ex As Exception
Return False
End Try
End Function
End Class

View File

@ -27,7 +27,7 @@ Public Class EnvelopeModel
.Subject = pRow.ItemEx("SUBJECT", ""),
.Message = pRow.ItemEx("MESSAGE", ""),
.UserId = pRow.ItemEx("USER_ID", 0),
.Status = ObjectEx.ToEnum(Of Constants.EnvelopeStatus)(pRow.ItemEx("STATUS", Constants.EnvelopeStatus.Created.ToString())),
.Status = ObjectEx.ToEnum(Of Constants.EnvelopeStatus)(pRow.ItemEx("STATUS", Constants.EnvelopeStatus.EnvelopeCreated.ToString())),
.AddedWhen = pRow.Item("ADDED_WHEN"),
.User = New User()
}
@ -57,6 +57,18 @@ Public Class EnvelopeModel
End Try
End Function
Public Function GetById(pEnvelopeId As String) As Envelope
Try
Dim oSql = $"SELECT * FROM [dbo].[TBSIG_ENVELOPE] WHERE GUID = '{pEnvelopeId}'"
Dim oTable = Database.GetDatatable(oSql)
Return ToEnvelope(oTable)
Catch ex As Exception
Logger.Error(ex)
Return Nothing
End Try
End Function
Public Function List() As IEnumerable(Of Envelope)
Try
Dim oSql = $"SELECT * FROM [dbo].[TBSIG_ENVELOPE] WHERE USER_ID = {State.UserId} AND STATUS IN (0,1,2,3)"
@ -102,25 +114,6 @@ Public Class EnvelopeModel
End Try
End Function
Public Function Send(pEnvelope As Envelope) As Boolean
Try
Dim oSql = "UPDATE [dbo].[TBSIG_ENVELOPE] SET STATUS = @STATUS, SENT_WHEN = GETDATE() WHERE GUID = @GUID"
Dim oCommand As New SqlCommand(oSql)
oCommand.Parameters.Add("GUID", SqlDbType.Int).Value = pEnvelope.Id
oCommand.Parameters.Add("STATUS", SqlDbType.Int).Value = Constants.EnvelopeStatus.Sent
If Database.ExecuteNonQuery(oCommand) Then
Return True
Else
Return False
End If
Catch ex As Exception
Logger.Error(ex)
Return False
End Try
End Function
Public Function Insert(pEnvelope As Envelope) As Boolean
Try
Dim oSql = "INSERT INTO [dbo].[TBSIG_ENVELOPE] (SUBJECT, MESSAGE, ENVELOPE_UUID, STATUS, USER_ID, TITLE, CONTRACT_TYPE) "
@ -129,7 +122,7 @@ Public Class EnvelopeModel
oCommand.Parameters.Add("SUBJECT", SqlDbType.NVarChar).Value = String.Empty
oCommand.Parameters.Add("MESSAGE", SqlDbType.NVarChar).Value = String.Empty
oCommand.Parameters.Add("UUID", SqlDbType.NVarChar).Value = pEnvelope.Uuid
oCommand.Parameters.Add("STATUS", SqlDbType.Int).Value = Constants.EnvelopeStatus.Created
oCommand.Parameters.Add("STATUS", SqlDbType.Int).Value = Constants.EnvelopeStatus.EnvelopeCreated
oCommand.Parameters.Add("USER_ID", SqlDbType.Int).Value = pEnvelope.UserId
oCommand.Parameters.Add("TITLE", SqlDbType.NVarChar).Value = pEnvelope.Title
oCommand.Parameters.Add("CONTRACT_TYPE", SqlDbType.Int).Value = pEnvelope.ContractType
@ -179,7 +172,7 @@ Public Class EnvelopeModel
Public Function Delete(pEnvelope As Envelope, pTransaction As SqlTransaction) As Boolean
Try
Dim oSql = $"DELETE FROM [dbo].[TBSIG_ENVELOPE] WHERE GUID = {pEnvelope.Id}"
Return Database.ExecuteNonQuery(oSql, pTransaction)
'Return Database.ExecuteNonQuery(oSql, pTransaction)
Catch ex As Exception
Return False

View File

@ -7,46 +7,24 @@ Public Class HistoryModel
MyBase.New(pState)
End Sub
Private Function GetActionDescription(pActionType As Constants.EnvelopeHistoryActionType)
Select Case pActionType
Case Constants.EnvelopeHistoryActionType.Created
Return "Umschlag erfolgreich erstellt"
Case Constants.EnvelopeHistoryActionType.Sent
Return "Umschlag an Empfänger versendet"
Case Constants.EnvelopeHistoryActionType.Seen
Return "Umschlag von Empfänger geöffnet"
Case Constants.EnvelopeHistoryActionType.Signed
Return "Umschlag von Empfänger signiert"
Case Else
Return pActionType.ToString()
End Select
End Function
Public Function Insert(pHistory As EnvelopeHistoryEntry) As Boolean
Try
Dim oSql = "INSERT INTO [dbo].[TBSIG_ENVELOPE_HISTORY] "
oSql += " ([ENVELOPE_ID] "
oSql += " ,[USER_REFERENCE] "
oSql += " ,[ACTION_TYPE] "
oSql += " ,[ACTION_DESCRIPTION] "
oSql += " ,[STATUS] "
oSql += " ,[ACTION_DATE]) "
oSql += " VALUES "
oSql += " (@ENVELOPE_ID "
oSql += " ,@USER_REFERENCE "
oSql += " ,@ACTION_TYPE "
oSql += " ,@ACTION_DESCRIPTION "
oSql += " ,@STATUS "
oSql += " ,@ACTION_DATE) "
Dim oCommand As New SqlCommand(oSql)
oCommand.Parameters.Add("ENVELOPE_ID", SqlDbType.Int).Value = pHistory.EnvelopeId
oCommand.Parameters.Add("USER_REFERENCE", SqlDbType.NVarChar).Value = pHistory.UserReference
oCommand.Parameters.Add("ACTION_TYPE", SqlDbType.Int).Value = pHistory.ActionType
oCommand.Parameters.Add("ACTION_DESCRIPTION", SqlDbType.NVarChar).Value = GetActionDescription(pHistory.ActionType)
oCommand.Parameters.Add("ACTION_DATE", SqlDbType.DateTime).Value = Now()
oCommand.Parameters.Add("STATUS", SqlDbType.Int).Value = pHistory.Status
oCommand.Parameters.Add("ACTION_DATE", SqlDbType.DateTime).Value = pHistory.ActionDate
If Database.ExecuteNonQuery(oCommand) Then
Return True

View File

@ -23,6 +23,12 @@ Public Class ReceiverModel
}
End Function
Private Function ToReceiver(pTable As DataTable) As EnvelopeReceiver
Return pTable?.Rows.Cast(Of DataRow).
Select(AddressOf ToReceiver).
Single()
End Function
Public Function TestReceiverExists(pReceiver As EnvelopeReceiver) As Boolean
Try
Dim oGuid = Database.GetScalarValue($"SELECT COALESCE(GUID, 0) FROM TBSIG_RECEIVER WHERE EMAIL_ADDRESS = '{pReceiver.Email}'")
@ -140,13 +146,13 @@ Public Class ReceiverModel
End Try
End Function
Public Function ListReceivers(pExistingReceivers As IEnumerable(Of EnvelopeReceiver)) As IEnumerable(Of EnvelopeReceiver)
Public Function ListReceivers(pReceiversFromGrid As List(Of EnvelopeReceiver)) As IEnumerable(Of EnvelopeReceiver)
Try
If pExistingReceivers.Count = 0 Then
If pReceiversFromGrid.Count = 0 Then
Return New List(Of EnvelopeReceiver)
End If
Dim oAddresses = pExistingReceivers.Select(Function(r) $"'{r.Email}'").JoinToString(",")
Dim oAddresses = pReceiversFromGrid.Select(Function(r) $"'{r.Email}'").JoinToString(",")
Dim oSql = $"SELECT * FROM [dbo].[TBSIG_RECEIVER] WHERE EMAIL_ADDRESS IN ({oAddresses})"
Dim oTable = Database.GetDatatable(oSql)
@ -173,6 +179,19 @@ Public Class ReceiverModel
End Try
End Function
Public Function GetById(pReceiverId As Integer) As EnvelopeReceiver
Try
Dim oSql = $"SELECT * FROM [dbo].[VWSIG_ENVELOPE_RECEIVERS] WHERE GUID = {pReceiverId}"
Dim oTable = Database.GetDatatable(oSql)
Return ToReceiver(oTable)
Catch ex As Exception
Logger.Error(ex)
Return Nothing
End Try
End Function
Public Function GetReceiverIdBySignature(pSignature As String) As Integer
Try
Return Database.GetScalarValue($"SELECT GUID FROM TBSIG_RECEIVER WHERE SIGNATURE = '{pSignature}'")

View File

@ -0,0 +1,32 @@
Imports DigitalData.Modules.Base
Public Class ActionService
Inherits BaseClass
Private ReadOnly State As State
Private EmailService As EmailService
Private HistoryService As HistoryService
Public Sub New(pState As State)
MyBase.New(pState.LogConfig)
State = pState
EmailService = New EmailService(pState)
HistoryService = New HistoryService(pState)
End Sub
Public Function DeleteEnvelope(pEnvelope As Envelope) As Boolean
HistoryService.SetEnvelopeStatus(pEnvelope, Constants.EnvelopeStatus.EnvelopeDeleted, pEnvelope.User.Email)
For Each oReceiver As EnvelopeReceiver In pEnvelope.Receivers
EmailService.SendEnvelopeDeletedEmail(oReceiver.Id, pEnvelope.Id)
Next
Return True
End Function
End Class

View File

@ -1,18 +1,79 @@
Imports DigitalData.Modules.Base

Imports DigitalData.Modules.Base
Imports DigitalData.Modules.Logging
Public Class EmailService
Inherits BaseClass
Private ReadOnly State As State
Private ReadOnly EnvelopeModel As EnvelopeModel
Private ReadOnly ReceiverModel As ReceiverModel
Private ReadOnly EmailModel As EmailModel
Private ReadOnly EmailTemplate As EmailTemplate
Public Sub New(pState As State)
MyBase.New(pState.LogConfig)
State = pState
EnvelopeModel = New EnvelopeModel(pState)
ReceiverModel = New ReceiverModel(pState)
EmailModel = New EmailModel(pState)
EmailTemplate = New EmailTemplate()
End Sub
Public Function SendSignedEmail(pReceiverId As Integer, pEnvelopeId As Integer)
Public Function SendEnvelopeDeletedEmail(pReceiverId As Integer, pEnvelopeId As Integer) As Boolean
Dim oEnvelope = EnvelopeModel.GetById(pEnvelopeId)
Dim oReceiver = ReceiverModel.GetById(pReceiverId)
Dim oEnvelope =
Dim oEmailData As New EmailData(oEnvelope, oReceiver) With
{
.SignatureLink = ""
}
EmailTemplate.FillEnvelopeDeletedEmailBody(oEmailData)
If EmailModel.Insert(oEmailData) = False Then
Logger.Error("EMail data could not be inserted.")
Return False
End If
Return True
End Function
Public Function SendInitialEmail(pReceiverId As Integer, pEnvelopeId As Integer) As Boolean
Dim oEnvelope = EnvelopeModel.GetById(pEnvelopeId)
Dim oReceiver = ReceiverModel.GetById(pReceiverId)
Dim oEmailData As New EmailData(oEnvelope, oReceiver) With
{
.SignatureLink = Helpers.GetEnvelopeURL(State.DbConfig.SignatureHost, oEnvelope.Uuid, oReceiver.Signature)
}
EmailTemplate.FillDocumentReceivedEmailBody(oEmailData)
If EmailModel.Insert(oEmailData) = False Then
Logger.Error("EMail data could not be inserted.")
Return False
End If
Return True
End Function
Public Function SendSignedEmail(pReceiverId As Integer, pEnvelopeId As Integer) As Boolean
Dim oEnvelope = EnvelopeModel.GetById(pEnvelopeId)
Dim oReceiver = ReceiverModel.GetById(pReceiverId)
Dim oEmailData = New EmailData(oEnvelope, oReceiver) With {.SignatureLink = ""}
EmailTemplate.FillDocumentSignedEmailBody(oEmailData)
If EmailModel.Insert(oEmailData) = False Then
Logger.Error("EMail data could not be inserted.")
Return False
End If
Return True
End Function

View File

@ -0,0 +1,32 @@

Imports DigitalData.Modules.Base
Imports DigitalData.Modules.Logging
Imports EnvelopeGenerator.Common.Constants
Public Class HistoryService
Inherits BaseClass
Private ReadOnly State As State
Private ReadOnly EnvelopeModel As EnvelopeModel
Private ReadOnly ReceiverModel As ReceiverModel
Private ReadOnly HistoryModel As HistoryModel
Public Sub New(pState As State)
MyBase.New(pState.LogConfig)
State = pState
EnvelopeModel = New EnvelopeModel(pState)
ReceiverModel = New ReceiverModel(pState)
HistoryModel = New HistoryModel(pState)
End Sub
Public Function SetEnvelopeStatus(pEnvelope As Envelope, pStatus As EnvelopeStatus, pUserReference As String) As Boolean
Return HistoryModel.Insert(New EnvelopeHistoryEntry() With {
.EnvelopeId = pEnvelope.Id,
.ActionDate = Now(),
.Status = pStatus,
.UserReference = pUserReference
})
End Function
End Class

View File

@ -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()

View File

@ -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)

View File

@ -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

View File

@ -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="&gt;&gt;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>

View File

@ -9,10 +9,10 @@ namespace EnvelopeGenerator.Web.Controllers
private readonly EnvelopeService envelopeService;
private readonly EmailService emailService;
public EnvelopeController(DatabaseService database, LoggingService logging, EnvelopeService envelope, EmailService email) : base(database, logging)
public EnvelopeController(DatabaseService database, LoggingService logging, EnvelopeService envelope) : base(database, logging)
{
envelopeService = envelope;
emailService = email;
emailService = new(state);
}
[HttpGet]
@ -62,7 +62,7 @@ namespace EnvelopeGenerator.Web.Controllers
envelopeService.InsertHistoryEntrySigned(response);
SendSignedEmail(response);
emailService.SendSignedEmail(response.Receiver.Id, response.Envelope.Id);
return Ok();
}
@ -71,18 +71,5 @@ namespace EnvelopeGenerator.Web.Controllers
return ErrorResponse(e);
}
}
public bool SendSignedEmail(EnvelopeResponse response)
{
EmailTemplate template = new();
EmailData emailData = new(response.Envelope, response.Receiver)
{
SignatureLink = "",
};
template.FillDocumentSignedEmailBody(emailData);
return emailService.SendEmail(emailData);
}
}
}

View File

@ -5,11 +5,6 @@ using static EnvelopeGenerator.Common.Constants;
namespace EnvelopeGenerator.Web.Controllers
{
public class ActionObject
{
public int ActionType { get; set; }
}
public class HistoryController : BaseController
{
private readonly EnvelopeService envelopeService;
@ -21,7 +16,7 @@ namespace EnvelopeGenerator.Web.Controllers
[HttpPost]
[Route("api/history/{envelopeKey}")]
public IActionResult Get(string envelopeKey, [FromBody] ActionObject action)
public IActionResult Get(string envelopeKey)
{
try
{
@ -30,12 +25,11 @@ namespace EnvelopeGenerator.Web.Controllers
// Validate Envelope Key and load envelope
envelopeService.EnsureValidEnvelopeKey(envelopeKey);
EnvelopeResponse response = envelopeService.LoadEnvelope(envelopeKey);
EnvelopeHistoryActionType actionType = (EnvelopeHistoryActionType)action.ActionType;
envelopeService.InsertHistoryEntry(new EnvelopeHistoryEntry()
{
ActionDate = DateTime.Now,
ActionType = actionType,
Status = EnvelopeStatus.DocumentOpened,
EnvelopeId = response.Envelope.Id,
UserReference = response.Receiver.Email
});

View File

@ -11,7 +11,6 @@ namespace EnvelopeGenerator.Web
// Add base services
builder.Services.AddSingleton<LoggingService>();
builder.Services.AddTransient<DatabaseService>();
builder.Services.AddTransient<EmailService>();
// Add higher order services
builder.Services.AddSingleton<EnvelopeService>();

View File

@ -1,38 +0,0 @@
using EnvelopeGenerator.Common;
namespace EnvelopeGenerator.Web.Services
{
public class EmailService : BaseService
{
private ReceiverModel receiverModel;
private EnvelopeModel envelopeModel;
private HistoryModel historyModel;
private DocumentModel documentModel;
private DocumentStatusModel documentStatusModel;
private EmailModel emailModel;
public EmailService(IConfiguration Config, LoggingService Logging, DatabaseService database) : base(Config, Logging)
{
logger = Logging.LogConfig.GetLogger();
if (database.Models == null)
{
throw new ArgumentNullException("Models not loaded.");
}
receiverModel = database.Models.receiverModel;
envelopeModel = database.Models.envelopeModel;
historyModel = database.Models.historyModel;
documentModel = database.Models.documentModel;
documentStatusModel = database.Models.documentStatusModel;
emailModel = database.Models.emailModel;
}
public bool SendEmail(EmailData emailData)
{
return emailModel.Insert(emailData);
}
}
}

View File

@ -111,7 +111,7 @@ namespace EnvelopeGenerator.Web.Services
return historyModel.Insert(new EnvelopeHistoryEntry()
{
ActionDate = DateTime.Now,
ActionType = EnvelopeHistoryActionType.Signed,
Status = EnvelopeStatus.DocumentSigned,
EnvelopeId = response.Envelope.Id,
UserReference = response.Receiver.Email
});

View File

@ -90,7 +90,7 @@ class App {
)
const createdAnnotations = await this.Instance.create(annotations)
await this.Network.postHistory(this.envelopeKey, ActionType.Seen)
await this.Network.postHistory(this.envelopeKey)
} catch (e) {
console.error(e)
}

View File

@ -32,20 +32,16 @@
})
}
postHistory(envelopeKey, actionType) {
postHistory(envelopeKey) {
const url = `/api/history/${envelopeKey}`
const data = {
actionType: actionType,
}
const options = {
credentials: 'include',
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
body: JSON.stringify(data),
body: JSON.stringify({}),
}
console.debug('PostHistory/Calling url: ' + url)