29-11-2023
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}'")
|
||||
|
||||
32
EnvelopeGenerator.Common/Services/ActionService.vb
Normal file
32
EnvelopeGenerator.Common/Services/ActionService.vb
Normal 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
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
32
EnvelopeGenerator.Common/Services/HistoryService.vb
Normal file
32
EnvelopeGenerator.Common/Services/HistoryService.vb
Normal 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
|
||||
Reference in New Issue
Block a user