2023-08-07
This commit is contained in:
15
EnvelopeGenerator.Common/Models/BaseModel.vb
Normal file
15
EnvelopeGenerator.Common/Models/BaseModel.vb
Normal file
@@ -0,0 +1,15 @@
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports System.Data
|
||||
|
||||
Public MustInherit Class BaseModel
|
||||
Protected Database As MSSQLServer
|
||||
Protected Logger As Logger
|
||||
Protected State As State
|
||||
|
||||
Public Sub New(pState As State)
|
||||
Logger = pState.LogConfig.GetLogger()
|
||||
Database = pState.Database
|
||||
State = pState
|
||||
End Sub
|
||||
End Class
|
||||
33
EnvelopeGenerator.Common/Models/DocumentModel.vb
Normal file
33
EnvelopeGenerator.Common/Models/DocumentModel.vb
Normal file
@@ -0,0 +1,33 @@
|
||||
Imports System.Data
|
||||
Imports DigitalData.Modules.Base
|
||||
Public Class DocumentModel
|
||||
Inherits BaseModel
|
||||
|
||||
Public Sub New(pState As State)
|
||||
MyBase.New(pState)
|
||||
End Sub
|
||||
|
||||
Private Function ToDocument(pRow As DataRow) As EnvelopeDocument
|
||||
Return New EnvelopeDocument() With {
|
||||
.Id = pRow.ItemEx("GUID", 0),
|
||||
.EnvelopeId = pRow.ItemEx("ENVELOPE_ID", 0),
|
||||
.FileInfo = New IO.FileInfo(pRow.ItemEx("FILEPATH", "")),
|
||||
.IsTempFile = False
|
||||
}
|
||||
End Function
|
||||
|
||||
Public Function List(pEnvelopeId As Integer) As IEnumerable(Of EnvelopeDocument)
|
||||
Try
|
||||
Dim oSql = $"SELECT * FROM [dbo].[TBSIG_ENVELOPE_DOCUMENT] WHERE ENVELOPE_ID = {pEnvelopeId}"
|
||||
Dim oTable = Database.GetDatatable(oSql)
|
||||
|
||||
Return oTable?.Rows.Cast(Of DataRow).
|
||||
Select(AddressOf ToDocument).
|
||||
ToList()
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
56
EnvelopeGenerator.Common/Models/ElementModel.vb
Normal file
56
EnvelopeGenerator.Common/Models/ElementModel.vb
Normal file
@@ -0,0 +1,56 @@
|
||||
Imports System.Data
|
||||
Imports DigitalData.Modules.Base
|
||||
|
||||
Public Class ElementModel
|
||||
Inherits BaseModel
|
||||
|
||||
Public Sub New(pState As State)
|
||||
MyBase.New(pState)
|
||||
End Sub
|
||||
|
||||
Private Function ToElement(pRow As DataRow) As EnvelopeDocumentElement
|
||||
Return New EnvelopeDocumentElement() With {
|
||||
.Id = pRow.ItemEx("GUID", 0),
|
||||
.DocumentId = pRow.ItemEx("DOCUMENT_ID", 0),
|
||||
.ReceiverId = pRow.ItemEx("RECEIVER_ID", 0),
|
||||
.ElementType = [Enum].Parse(GetType(Constants.ElementType), pRow.ItemEx("ELEMENT_TYPE", Constants.ElementType.Signature.ToString)),
|
||||
.X = pRow.ItemEx("POSITION_X", 0.0),
|
||||
.Y = pRow.ItemEx("POSITION_Y", 0.0),
|
||||
.Width = pRow.ItemEx("WIDTH", 0.0),
|
||||
.Height = pRow.ItemEx("HEIGHT", 0.0),
|
||||
.Page = pRow.ItemEx("PAGE", 0),
|
||||
.AnnotationIndex = pRow.ItemEx("ANNOTATION_INDEX", 0)
|
||||
}
|
||||
End Function
|
||||
|
||||
Public Function ElementsExist(pEnvelopeId As Integer, pReceiverId As Integer) As Boolean
|
||||
Try
|
||||
Dim oSql = $"SELECT COUNT(*) FROM [dbo].[TBSIG_DOCUMENT_RECEIVER_ELEMENT] T
|
||||
JOIN TBSIG_ENVELOPE_DOCUMENT T2 ON T.DOCUMENT_ID = T2.GUID
|
||||
WHERE T.RECEIVER_ID = {pReceiverId} AND T2.ENVELOPE_ID = {pEnvelopeId}"
|
||||
Dim oElementCount As Integer = Database.GetScalarValue(oSql)
|
||||
|
||||
Return oElementCount > 0
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function List(pDocumentId As Integer) As List(Of EnvelopeDocumentElement)
|
||||
Try
|
||||
Dim oSql = $"SELECT * FROM [dbo].[TBSIG_DOCUMENT_RECEIVER_ELEMENT] WHERE DOCUMENT_ID = {pDocumentId} ORDER BY PAGE ASC, ANNOTATION_INDEX ASC"
|
||||
Dim oTable = Database.GetDatatable(oSql)
|
||||
|
||||
Return oTable?.Rows.Cast(Of DataRow).
|
||||
Select(AddressOf ToElement).
|
||||
ToList()
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
End Class
|
||||
102
EnvelopeGenerator.Common/Models/EnvelopeModel.vb
Normal file
102
EnvelopeGenerator.Common/Models/EnvelopeModel.vb
Normal file
@@ -0,0 +1,102 @@
|
||||
Imports System.Data.SqlClient
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Base
|
||||
Imports System.Data
|
||||
|
||||
Public Class EnvelopeModel
|
||||
Inherits BaseModel
|
||||
|
||||
Public Sub New(pState As State)
|
||||
MyBase.New(pState)
|
||||
End Sub
|
||||
|
||||
Private Function ToEnvelope(pRow As DataRow) As Envelope
|
||||
Dim oEnvelope = New Envelope() With {
|
||||
.Id = pRow.ItemEx("GUID", 0),
|
||||
.Uuid = pRow.ItemEx("ENVELOPE_UUID", ""),
|
||||
.Subject = pRow.ItemEx("SUBJECT", ""),
|
||||
.Message = pRow.ItemEx("MESSAGE", ""),
|
||||
.UserId = State.UserId,
|
||||
.Status = ObjectEx.ToEnum(Of Constants.EnvelopeStatus)(pRow.ItemEx("STATUS", "Created"))
|
||||
}
|
||||
|
||||
Return oEnvelope
|
||||
End Function
|
||||
|
||||
Public Function List() As IEnumerable(Of Envelope)
|
||||
Try
|
||||
Dim oSql = $"SELECT * FROM [dbo].[TBSIG_ENVELOPE] WHERE USER_ID = {State.UserId}"
|
||||
Dim oTable = Database.GetDatatable(oSql)
|
||||
|
||||
Return oTable?.Rows.Cast(Of DataRow).
|
||||
Select(AddressOf ToEnvelope).
|
||||
ToList()
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
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) VALUES (@SUBJECT, @MESSAGE, @UUID, @STATUS, @USER_ID)"
|
||||
Dim oCommand As New SqlCommand(oSql)
|
||||
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.NVarChar).Value = Constants.EnvelopeStatus.Created
|
||||
oCommand.Parameters.Add("USER_ID", SqlDbType.Int).Value = pEnvelope.UserId
|
||||
|
||||
If Database.ExecuteNonQuery(oCommand) Then
|
||||
pEnvelope.Id = GetEnvelopeId(pEnvelope)
|
||||
Return True
|
||||
Else
|
||||
Return False
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function Update(pEnvelope As Envelope, pTransaction As SqlTransaction) As Boolean
|
||||
Try
|
||||
Dim oSql = "UPDATE [dbo].[TBSIG_ENVELOPE] SET [SUBJECT] = @SUBJECT, [MESSAGE] = @MESSAGE, [STATUS] = @STATUS WHERE GUID = @ID AND USER_ID = @USER_ID"
|
||||
Dim oCommand As New SqlCommand(oSql)
|
||||
oCommand.Parameters.Add("SUBJECT", SqlDbType.NVarChar).Value = pEnvelope.Subject
|
||||
oCommand.Parameters.Add("MESSAGE", SqlDbType.NVarChar).Value = pEnvelope.Message
|
||||
oCommand.Parameters.Add("STATUS", SqlDbType.NVarChar).Value = pEnvelope.Status
|
||||
|
||||
oCommand.Parameters.Add("ID", SqlDbType.Int).Value = pEnvelope.Id
|
||||
oCommand.Parameters.Add("USER_ID", SqlDbType.Int).Value = pEnvelope.UserId
|
||||
|
||||
Return Database.ExecuteNonQuery(oCommand, pTransaction)
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function Delete(pEnvelope As Envelope) As Boolean
|
||||
Try
|
||||
Dim oSql = $"DELETE FROM [dbo].[TBSIG_ENVELOPE] WHERE GUID = {pEnvelope.Id}"
|
||||
Return Database.ExecuteNonQuery(oSql)
|
||||
|
||||
Catch ex As Exception
|
||||
Return False
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function GetEnvelopeId(pEnvelope As Envelope) As Integer
|
||||
Try
|
||||
Return Database.GetScalarValue($"SELECT MAX(GUID) FROM TBSIG_ENVELOPE WHERE USER_ID = {pEnvelope.UserId}")
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
43
EnvelopeGenerator.Common/Models/HistoryModel.vb
Normal file
43
EnvelopeGenerator.Common/Models/HistoryModel.vb
Normal file
@@ -0,0 +1,43 @@
|
||||
Imports System.Data
|
||||
Imports System.Data.SqlClient
|
||||
|
||||
Public Class HistoryModel
|
||||
Inherits BaseModel
|
||||
|
||||
Public Sub New(pState As State)
|
||||
MyBase.New(pState)
|
||||
End Sub
|
||||
|
||||
Public Function Insert(pHistory As EnvelopeHistoryEntry) As Boolean
|
||||
Try
|
||||
Dim oSql = "INSERT INTO [dbo].[TBSIG_ENVELOPE_HISTORY]
|
||||
([ENVELOPE_ID]
|
||||
,[STATUS]
|
||||
,[USER_EMAIL_ADDRESS]
|
||||
,[ACTION_TITLE]
|
||||
,[ACTION_DESCRIPTION])
|
||||
VALUES
|
||||
(@ENVELOPE_ID
|
||||
,@STATUS
|
||||
,@EMAIL
|
||||
,@TITLE
|
||||
,@DESCRIPTION"
|
||||
|
||||
Dim oCommand As New SqlCommand(oSql)
|
||||
oCommand.Parameters.Add("ENVELOPE_ID", SqlDbType.Int).Value = pHistory.EnvelopeId
|
||||
oCommand.Parameters.Add("STATUS", SqlDbType.NVarChar).Value = pHistory.Status
|
||||
oCommand.Parameters.Add("EMAIL", SqlDbType.NVarChar).Value = pHistory.UserEmailAddress
|
||||
oCommand.Parameters.Add("TITLE", SqlDbType.NVarChar).Value = pHistory.ActionTitle
|
||||
oCommand.Parameters.Add("DESCRIPTION", SqlDbType.NVarChar).Value = pHistory.ActionDescription
|
||||
|
||||
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
|
||||
159
EnvelopeGenerator.Common/Models/ReceiverModel.vb
Normal file
159
EnvelopeGenerator.Common/Models/ReceiverModel.vb
Normal file
@@ -0,0 +1,159 @@
|
||||
Imports System.Data
|
||||
Imports System.Data.Common
|
||||
Imports System.Data.SqlClient
|
||||
Imports DigitalData.Modules.Base
|
||||
Public Class ReceiverModel
|
||||
Inherits BaseModel
|
||||
|
||||
Public Sub New(pState As State)
|
||||
MyBase.New(pState)
|
||||
End Sub
|
||||
|
||||
Private Function ToReceiver(pRow As DataRow) As EnvelopeReceiver
|
||||
Return New EnvelopeReceiver() With {
|
||||
.Id = pRow.ItemEx("GUID", 0),
|
||||
.Email = pRow.ItemEx("EMAIL_ADDRESS", ""),
|
||||
.Name = pRow.ItemEx("NAME", ""),
|
||||
.Sequence = pRow.ItemEx("SEQUENCE", 0)
|
||||
}
|
||||
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}'")
|
||||
pReceiver.Id = oGuid
|
||||
Return oGuid > 0
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function Insert(pReceiver As EnvelopeReceiver, pTransaction As SqlTransaction) As Boolean
|
||||
Try
|
||||
Dim oSql As String = "INSERT INTO [dbo].[TBSIG_RECEIVER]
|
||||
([EMAIL_ADDRESS]
|
||||
,[SIGNATURE])
|
||||
VALUES
|
||||
(@EMAIL
|
||||
,@SIGNATURE)"
|
||||
|
||||
Dim oCommand = New SqlCommand(oSql)
|
||||
oCommand.Parameters.Add("EMAIL", SqlDbType.NVarChar).Value = pReceiver.Email
|
||||
oCommand.Parameters.Add("SIGNATURE", SqlDbType.NVarChar).Value = pReceiver.Signature
|
||||
|
||||
Dim oResult = Database.ExecuteNonQuery(oCommand, pTransaction)
|
||||
If oResult = True Then
|
||||
pReceiver.Id = GetReceiverId(pReceiver.Email, pTransaction)
|
||||
Else
|
||||
Return False
|
||||
End If
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function Update(pReceiver As EnvelopeReceiver, pTransaction As SqlTransaction) As Boolean
|
||||
Try
|
||||
Dim oSql As String = "UPDATE [dbo].[TBSIG_USER_RECEIVER]
|
||||
SET [NAME] = @NAME
|
||||
,[COMPANY_NAME] = @COMPANY
|
||||
,[JOB_TITLE] = @JOB
|
||||
WHERE RECEIVER_ID = @RECEIVER_ID"
|
||||
|
||||
Dim oCommand = New SqlCommand(oSql)
|
||||
oCommand.Parameters.Add("NAME", SqlDbType.NVarChar).Value = pReceiver.Name
|
||||
oCommand.Parameters.Add("COMPANY", SqlDbType.NVarChar).Value = pReceiver.Company
|
||||
oCommand.Parameters.Add("JOB", SqlDbType.NVarChar).Value = pReceiver.JobTitle
|
||||
oCommand.Parameters.Add("RECEIVER_ID", SqlDbType.Int).Value = pReceiver.Id
|
||||
oCommand.Parameters.Add("USER_ID", SqlDbType.Int).Value = pReceiver.Id
|
||||
|
||||
Return Database.ExecuteNonQuery(oCommand, pTransaction)
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function Unassign(pEnvelope As Envelope, pTransaction As SqlTransaction) As Boolean
|
||||
Try
|
||||
Return Database.ExecuteNonQuery($"DELETE FROM [dbo].[TBSIG_ENVELOPE_RECEIVER] WHERE [ENVELOPE_ID] = {pEnvelope.Id}", pTransaction)
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function Assign(pEnvelope As Envelope, pReceiver As EnvelopeReceiver, pTransaction As SqlTransaction) As Boolean
|
||||
Dim oSql = "INSERT INTO [dbo].[TBSIG_ENVELOPE_RECEIVER]
|
||||
([ENVELOPE_ID]
|
||||
,[RECEIVER_ID]
|
||||
,[PRIVATE_MESSAGE]
|
||||
,[ACCESS_CODE]
|
||||
,[NAME]
|
||||
,[JOB_TITLE]
|
||||
,[COMPANY_NAME]
|
||||
,[SEQUENCE])
|
||||
VALUES
|
||||
(@ENVELOPE_ID
|
||||
,@RECEIVER_ID
|
||||
,@MESSAGE
|
||||
,@ACCESS_CODE
|
||||
,@NAME
|
||||
,@JOB
|
||||
,@COMPANY
|
||||
,@SEQUENCE)"
|
||||
|
||||
Dim oCommand As New SqlCommand(oSql)
|
||||
oCommand.Parameters.Add("ENVELOPE_ID", SqlDbType.NVarChar).Value = pEnvelope.Id
|
||||
oCommand.Parameters.Add("RECEIVER_ID", SqlDbType.NVarChar).Value = pReceiver.Id
|
||||
oCommand.Parameters.Add("MESSAGE", SqlDbType.NVarChar).Value = pReceiver.PrivateMessage
|
||||
oCommand.Parameters.Add("ACCESS_CODE", SqlDbType.NVarChar).Value = pReceiver.AccessCode
|
||||
oCommand.Parameters.Add("NAME", SqlDbType.NVarChar).Value = pReceiver.Name
|
||||
oCommand.Parameters.Add("JOB", SqlDbType.NVarChar).Value = pReceiver.JobTitle
|
||||
oCommand.Parameters.Add("COMPANY", SqlDbType.NVarChar).Value = pReceiver.Company
|
||||
oCommand.Parameters.Add("SEQUENCE", SqlDbType.NVarChar).Value = pReceiver.Sequence
|
||||
|
||||
Return Database.ExecuteNonQuery(oCommand, pTransaction)
|
||||
End Function
|
||||
|
||||
Public Function List(pEnvelopeId As Integer) As IEnumerable(Of EnvelopeReceiver)
|
||||
Try
|
||||
Dim oSql = $"SELECT * FROM [dbo].[VWSIG_ENVELOPE_RECEIVERS] WHERE ENVELOPE_ID = {pEnvelopeId}"
|
||||
Dim oTable = Database.GetDatatable(oSql)
|
||||
|
||||
Return oTable?.Rows.Cast(Of DataRow).
|
||||
Select(AddressOf ToReceiver).
|
||||
ToList()
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function Delete(pReceiverId As Integer, pDocumentId As Integer) As Boolean
|
||||
Try
|
||||
Dim oSql = $"DELETE FROM TBSIG_DOCUMENT_RECEIVER WHERE RECEIVER_ID = {pReceiverId} AND DOCUMENT_ID = {pDocumentId}"
|
||||
Return Database.ExecuteNonQuery(oSql)
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function GetReceiverId(pEmailAddress As String, pTransaction As SqlTransaction) As Integer
|
||||
Try
|
||||
Return Database.GetScalarValue($"SELECT GUID FROM TBSIG_RECEIVER WHERE EMAIL_ADDRESS = '{pEmailAddress}'", pTransaction)
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
Reference in New Issue
Block a user