Refactor email content logic into EmailData class

Move dynamic message and signature type logic from TemplateService to EmailData via DynamicStringsForEmails. Constructors now set and HTML-encode these properties. Improves maintainability by centralizing email content generation.
This commit is contained in:
OlgunR
2026-03-03 10:42:18 +01:00
parent a7fff24f80
commit af60dfe338
2 changed files with 23 additions and 12 deletions

View File

@@ -23,6 +23,18 @@ Public Class EmailData
Public Property ADDED_WHO_PROCESS As String = "DDEnvelopGenerator"
Public ReadOnly Property EnvelopeTypeId As Integer = 0
Public Property SignatureType As String = ""
Public Sub DynamicStringsForEmails(pEnvelope As Entities.Envelope)
If pEnvelope.EnvelopeTypeId = 1 Then
SignatureType = "Signieren"
Message = "Bitte lesen und unterzeichnen Sie dieses Dokument."
ElseIf pEnvelope.EnvelopeTypeId = 2 Then
SignatureType = "Lesen und bestätigen"
Message = "Bitte lesen und bestätigen Sie, dieses Dokument gelesen zu haben."
End If
End Sub
''' <summary>
''' Constructor for sending email to receiver
@@ -31,11 +43,14 @@ Public Class EmailData
''' <param name="pReceiver"></param>
''' <param name="pStatus"></param>
Public Sub New(pEnvelope As Entities.Envelope, pReceiver As Receiver, pStatus As Constants.EnvelopeStatus)
DynamicStringsForEmails(pEnvelope)
EmailAdress = pReceiver.EmailAddress
EmailSubject = String.Empty
EmailType = pStatus
Message = TextToHtml(pEnvelope.Message)
Message = TextToHtml(Message)
ReferenceID = pEnvelope.Id
ReferenceString = pEnvelope.Uuid
ReceiverName = pReceiver.Name
@@ -44,6 +59,7 @@ Public Class EmailData
SenderName = pEnvelope.User.GetFullName()
EnvelopeTitle = pEnvelope.Title
EnvelopeTypeId = pEnvelope.EnvelopeTypeId
SignatureType = TextToHtml(SignatureType)
End Sub
Public Function TextToHtml(input As String) As String
If String.IsNullOrEmpty(input) Then Return ""
@@ -68,11 +84,14 @@ Public Class EmailData
''' <param name="pEnvelope"></param>
''' <param name="pStatus"></param>
Public Sub New(pEnvelope As Entities.Envelope, pStatus As Constants.EnvelopeStatus)
DynamicStringsForEmails(pEnvelope)
EmailAdress = pEnvelope.User.Email
EmailSubject = String.Empty
EmailType = pStatus
Message = pEnvelope.Message
Message = TextToHtml(Message)
ReferenceID = pEnvelope.Id
ReferenceString = pEnvelope.Uuid
ReceiverName = pEnvelope.User.GetFullName()
@@ -81,6 +100,7 @@ Public Class EmailData
SenderName = pEnvelope.User.GetFullName()
EnvelopeTitle = pEnvelope.Title
EnvelopeTypeId = pEnvelope.EnvelopeTypeId
SignatureType = TextToHtml(SignatureType)
End Sub
End Class

View File

@@ -22,20 +22,11 @@ Public Class TemplateService
Private Sub InitDictionary(pEmailData As EmailData, Optional pReason As String = "")
Logger.Debug("Initializing dictionary..")
Dim signatureType As String
If pEmailData.EnvelopeTypeId = 1 Then
signatureType = "Signieren"
pEmailData.Message = "Bitte lesen und unterzeichnen Sie dieses Dokument."
ElseIf pEmailData.EnvelopeTypeId = 2 Then
signatureType = "Lesen und bestätigen"
pEmailData.Message = "Bitte lesen und bestätigen Sie, dieses Dokument gelesen zu haben."
End If
_replaceDictionary = New Dictionary(Of String, String) From {
{"[NAME_RECEIVER]", pEmailData.ReceiverName},
{"[NAME_SENDER]", pEmailData.SenderName},
{"[NAME_PORTAL]", DbConfig.ExternalProgramName},
{"[SIGNATURE_TYPE]", signatureType},
{"[SIGNATURE_TYPE]", pEmailData.SignatureType},
{"[LINK_TO_DOCUMENT]", pEmailData.SignatureLink},
{"[LINK_TO_DOCUMENT_TEXT]", $"{pEmailData.SignatureLink.Truncate(40)}.."},
{"[DOCUMENT_TITLE]", pEmailData.EnvelopeTitle},