Imports EnvelopeGenerator.Domain.Entities Imports EnvelopeGenerator.Domain.Constants Imports EnvelopeGenerator.Common.My.Resources Imports DigitalData.Modules.Database Public Class ActionService Inherits BaseService Private ReadOnly EmailService As EmailService Private ReadOnly HistoryService As HistoryService Private ReadOnly ReceiverModel As ReceiverModel Private myDatabase As MSSQLServer Public Sub New(pState As State, pDD_ECM As MSSQLServer) MyBase.New(pState) myDatabase = pDD_ECM EmailService = New EmailService(pState) HistoryService = New HistoryService(pState) ReceiverModel = New ReceiverModel(pState) End Sub Public Function SendEnvelope(pEnvelope As Domain.Entities.Envelope) As Boolean If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.EnvelopeQueued, pEnvelope.User.Email) = False Then Return False End If Dim oSendResult = pEnvelope.Receivers. Select(Function(r) EmailService.SendDocumentReceivedEmail(pEnvelope, r)). All(Function(r) r = True) If oSendResult = False Then Return False End If Return True End Function Public Function SetStatusDocumentRotationChanged(pEnvelope As Domain.Entities.Envelope) As Boolean If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.DocumentMod_Rotation, pEnvelope.User.Email) = False Then Return False End If Return True End Function Public Function Resend_Receiver(pEnvelope As Domain.Entities.Envelope, pmail As String) As Boolean If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.EnvelopeQueued, pEnvelope.User.Email) = False Then Return False End If Dim oSendResult As Boolean = False For Each oReceiver In pEnvelope.Receivers EmailService.SendDocumentReceivedEmail(pEnvelope, oReceiver) Next Return oSendResult End Function Public Function ResendReceiver(pEnvelope As Domain.Entities.Envelope, pReceiver As Receiver) As Boolean Return EmailService.SendDocumentReceivedEmail(pEnvelope, pReceiver) End Function Public Function DeleteEnvelope(pEnvelope As Domain.Entities.Envelope, pReason As String) As Boolean Dim oStatus As EnvelopeStatus If pEnvelope.IsAlreadySent Then oStatus = EnvelopeStatus.EnvelopeWithdrawn Else oStatus = EnvelopeStatus.EnvelopeDeleted End If Dim oUpd = $"UPDATE TBSIG_ENVELOPE SET REJECTION_REASON = '{pReason}' WHERE GUID = {pEnvelope.Id}" myDatabase.ExecuteNonQuery(oUpd) If HistoryService.SetEnvelopeStatus(pEnvelope, oStatus, pEnvelope.User.Email) = False Then Return False End If Dim oSendResult = pEnvelope.Receivers. Select(Function(r) EmailService.SendEnvelopeDeletedEmail(pEnvelope, r, pReason)). All(Function(r) r = True) If oSendResult = False Then Return False End If Return True End Function Public Function API_SendWithdrawn_Mails(pEnvelope As Domain.Entities.Envelope, pReason As String) As Boolean Dim oSendResult As Boolean = False For Each oReceiver As Receiver In pEnvelope.Receivers If EmailService.SendEnvelopeDeletedEmail(pEnvelope, oReceiver, pReason) = False Then Return False End If Next Return True End Function Public Function OpenEnvelope(pEnvelope As Domain.Entities.Envelope, pReceiver As Receiver) As Boolean Dim oUserReference = pReceiver.EmailAddress If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.DocumentOpened, oUserReference) = False Then Return False End If Return True End Function Public Function RequestAccessCode(pEnvelope As Domain.Entities.Envelope, pReceiver As Receiver) As Boolean Dim oUserReference = pReceiver.EmailAddress If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.AccessCodeRequested, oUserReference) = False Then Return False End If Return True End Function Public Function EnterCorrectAccessCode(pEnvelope As Domain.Entities.Envelope, pReceiver As Receiver) As Boolean Dim oUserReference = pReceiver.EmailAddress If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.AccessCodeCorrect, oUserReference) = False Then Return False End If Return True End Function Public Function EnterIncorrectAccessCode(pEnvelope As Domain.Entities.Envelope, pReceiver As Receiver) As Boolean Dim oUserReference = pReceiver.EmailAddress If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.AccessCodeIncorrect, oUserReference) = False Then Return False End If Return True End Function Public Function SignEnvelope(pEnvelope As Domain.Entities.Envelope, pReceiver As Receiver) As Boolean Dim oUserReference = pReceiver.EmailAddress If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.DocumentSigned, oUserReference) = False Then Return False End If Return EmailService.SendSignedEmail(pEnvelope, pReceiver) End Function Public Function FinalizeEnvelope(pEnvelope As Domain.Entities.Envelope) As Boolean If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.EnvelopeArchived, "System") = False Then Return False End If Return True End Function Public Function CompleteEnvelope(pEnvelope As Domain.Entities.Envelope, pReceiver As Domain.Entities.Receiver) As Boolean ', pAttachment As String If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.MessageCompletionSent, pReceiver.EmailAddress) = False Then Return False End If Return EmailService.SendDocumentCompletedEmailToReceiver(pEnvelope, pReceiver) ', pAttachment End Function Public Function CompleteEnvelope(pEnvelope As Domain.Entities.Envelope) As Boolean ', pAttachment As String If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.MessageCompletionSent, pEnvelope.User.Email) = False Then Return False End If Return EmailService.SendDocumentCompletedEmailToCreator(pEnvelope) ', pAttachment End Function Public Function CreateReport(pEnvelope As Domain.Entities.Envelope) As Boolean If HistoryService.SetEnvelopeStatus(pEnvelope, EnvelopeStatus.EnvelopeReportCreated, "System") = False Then Return False End If Return True End Function End Class