TekH c5c040fb15 Refactor enum usage in codebase
Updated references from `Constants` to direct usage of `EnvelopeStatus` and `EmailTemplateType` enums. This change enhances code readability and reduces dependency on the `Constants` class.

Modified properties and parameters across command classes, DTOs, repositories, and services to use the enums directly. Updated `ModifyDocStatusCommandBase`, `EnvelopeHistoryDto`, and `ResetEmailTemplateCommand` for improved clarity.

Consistent updates across multiple files indicate a systematic refactoring aimed at streamlining the codebase and improving maintainability. Comments and documentation have also been revised to reflect these changes.
2025-09-01 11:04:40 +02:00

73 lines
2.8 KiB
VB.net

Imports System.Data.SqlClient
Imports DigitalData.Modules.Base
Imports EnvelopeGenerator.Domain.Entities
Public Class HistoryModel
Inherits BaseModel
Public Sub New(pState As State)
MyBase.New(pState)
End Sub
Private Function ToEnvelopeHistoryEntry(pRow As DataRow) As EnvelopeHistory
Return New EnvelopeHistory() With {
.ActionDate = pRow.ItemEx(Of Date)("ACTION_DATE", Nothing),
.EnvelopeId = pRow.Item("ENVELOPE_ID"),
.Status = pRow.Item("STATUS"),
.UserReference = pRow.ItemEx("USER_REFERENCE", "")
}
End Function
Public Function List(pEnvelopeId As Integer) As List(Of EnvelopeHistory)
Dim oSql = $"SELECT * FROM TBSIG_ENVELOPE_HISTORY WHERE ENVELOPE_ID = {pEnvelopeId} AND ACTION_DATE IS NOT NULL ORDER BY GUID DESC"
Dim oTable = Database.GetDatatable(oSql)
Return oTable?.Rows.
Cast(Of DataRow).
Select(AddressOf ToEnvelopeHistoryEntry).
ToList()
End Function
Public Function HasReceiverSigned(pEnvelopeId As Integer, pReceiverId As Integer) As Boolean
Dim oEnvelopeSigned As Integer = Domain.EnvelopeStatus.DocumentSigned
Dim oSql = $"SELECT COUNT(T.GUID)
FROM TBSIG_ENVELOPE_HISTORY T
JOIN TBSIG_RECEIVER T2 ON T.USER_REFERENCE = T2.EMAIL_ADDRESS
WHERE T.STATUS = {oEnvelopeSigned} AND
T.ENVELOPE_ID = {pEnvelopeId} AND
T2.GUID = {pReceiverId}"
Dim oRowCount As Integer = Database.GetScalarValue(oSql)
Return oRowCount > 0
End Function
Public Function Insert(pHistory As EnvelopeHistory) As Boolean
Try
Dim oSql = "INSERT INTO [dbo].[TBSIG_ENVELOPE_HISTORY] "
oSql += " ([ENVELOPE_ID] "
oSql += " ,[USER_REFERENCE] "
oSql += " ,[STATUS] "
oSql += " ,[ACTION_DATE]) "
oSql += " VALUES "
oSql += " (@ENVELOPE_ID "
oSql += " ,@USER_REFERENCE "
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("STATUS", SqlDbType.Int).Value = pHistory.Status
oCommand.Parameters.Add("ACTION_DATE", SqlDbType.DateTime).Value = pHistory.ActionDate
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
End Class