Add documentstatus
This commit is contained in:
89
EnvelopeGenerator.Common/Models/DocumentStatusModel.vb
Normal file
89
EnvelopeGenerator.Common/Models/DocumentStatusModel.vb
Normal file
@@ -0,0 +1,89 @@
|
||||
Imports System.Data.SqlClient
|
||||
|
||||
Public Class DocumentStatusModel
|
||||
Inherits BaseModel
|
||||
|
||||
Public Sub New(pState As State)
|
||||
MyBase.New(pState)
|
||||
End Sub
|
||||
|
||||
Public Function InsertOrUpdate(pDocumentStatus As DocumentStatus) As Boolean
|
||||
If pDocumentStatus.Id = 0 Then
|
||||
Return Insert(pDocumentStatus)
|
||||
Else
|
||||
Return Update(pDocumentStatus)
|
||||
End If
|
||||
End Function
|
||||
|
||||
Public Function Insert(pDocumentStatus As DocumentStatus) As Boolean
|
||||
Try
|
||||
Dim oSql = "INSERT INTO [dbo].[TBSIG_DOCUMENT_STATUS]
|
||||
([ENVELOPE_ID]
|
||||
,[RECEIVER_ID]
|
||||
,[STATUS]
|
||||
,[STATUS_CHANGED_WHEN]
|
||||
,[VALUE])
|
||||
VALUES
|
||||
(@ENVELOPE_ID
|
||||
,@RECEIVER_ID
|
||||
,@STATUS
|
||||
,@STATUS_CHANGED_WHEN
|
||||
,@VALUE)"
|
||||
|
||||
Dim oCommand As New SqlCommand(oSql)
|
||||
oCommand.Parameters.Add("ENVELOPE_ID", SqlDbType.Int).Value = pDocumentStatus.EnvelopeId
|
||||
oCommand.Parameters.Add("RECEIVER_ID", SqlDbType.Int).Value = pDocumentStatus.ReceiverId
|
||||
oCommand.Parameters.Add("STATUS", SqlDbType.NVarChar).Value = pDocumentStatus.Status.ToString()
|
||||
oCommand.Parameters.Add("STATUS_CHANGED_WHEN", SqlDbType.DateTime).Value = Now()
|
||||
oCommand.Parameters.Add("VALUE", SqlDbType.NVarChar).Value = pDocumentStatus.Value
|
||||
|
||||
If Database.ExecuteNonQuery(oCommand) Then
|
||||
pDocumentStatus.Id = GetElementId(pDocumentStatus)
|
||||
Return True
|
||||
Else
|
||||
Return False
|
||||
End If
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function Update(pDocumentStatus As DocumentStatus) As Boolean
|
||||
Try
|
||||
Dim oSql = "UPDATE [dbo].[TBSIG_DOCUMENT_STATUS]
|
||||
SET [STATUS] = @STATUS
|
||||
,[STATUS_CHANGED_WHEN] = @STATUS_CHANGED_WHEN
|
||||
,[CHANGED_WHEN] = @CHANGED_WHEN
|
||||
,[VALUE] = @VALUE
|
||||
WHERE GUID = @GUID"
|
||||
|
||||
Dim oCommand As New SqlCommand(oSql)
|
||||
oCommand.Parameters.Add("GUID", SqlDbType.Int).Value = pDocumentStatus.Id
|
||||
oCommand.Parameters.Add("STATUS", SqlDbType.NVarChar).Value = pDocumentStatus.Status.ToString()
|
||||
oCommand.Parameters.Add("STATUS_CHANGED_WHEN", SqlDbType.DateTime).Value = Now()
|
||||
oCommand.Parameters.Add("CHANGED_WHEN", SqlDbType.DateTime).Value = Now()
|
||||
oCommand.Parameters.Add("VALUE", SqlDbType.NVarChar).Value = pDocumentStatus.Value
|
||||
|
||||
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
|
||||
|
||||
Private Function GetElementId(pDocument As DocumentStatus) As Integer
|
||||
Try
|
||||
Return Database.GetScalarValue($"SELECT MAX(GUID) FROM TBSIG_DOCUMENT_STATUS
|
||||
WHERE ENVELOPE_ID = {pDocument.EnvelopeId} AND RECEIVER_ID = {pDocument.ReceiverId}")
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
Reference in New Issue
Block a user