diff --git a/EnvelopeGenerator.Common/Entities/ElementStatus.vb b/EnvelopeGenerator.Common/Entities/ElementStatus.vb new file mode 100644 index 00000000..c15a89c6 --- /dev/null +++ b/EnvelopeGenerator.Common/Entities/ElementStatus.vb @@ -0,0 +1,10 @@ +Public Class ElementStatus + + Public Property Id As Integer + Public Property EnvelopeId As Integer + Public Property ElementId As Integer + Public Property ElementValue As String + Public Property Status As Constants.ElementStatus = Constants.ElementStatus.Created + Public Property StatusChangedWhen As Date + +End Class diff --git a/EnvelopeGenerator.Common/Entities/EnvelopeDocumentElement.vb b/EnvelopeGenerator.Common/Entities/EnvelopeDocumentElement.vb index f99c9cb4..44395993 100644 --- a/EnvelopeGenerator.Common/Entities/EnvelopeDocumentElement.vb +++ b/EnvelopeGenerator.Common/Entities/EnvelopeDocumentElement.vb @@ -10,7 +10,6 @@ Public Property Required As Boolean = False Public Property [ReadOnly] As Boolean = False Public Property Page As Integer = 1 - Public Property Status As Constants.ElementStatus = Constants.ElementStatus.Created Public Property Index As Integer = 0 Public ReadOnly Property Top As Single diff --git a/EnvelopeGenerator.Common/EnvelopeGenerator.Common.vbproj b/EnvelopeGenerator.Common/EnvelopeGenerator.Common.vbproj index a8d06760..8524dff2 100644 --- a/EnvelopeGenerator.Common/EnvelopeGenerator.Common.vbproj +++ b/EnvelopeGenerator.Common/EnvelopeGenerator.Common.vbproj @@ -95,6 +95,7 @@ + @@ -111,6 +112,7 @@ + diff --git a/EnvelopeGenerator.Common/Models/ElementStatusModel.vb b/EnvelopeGenerator.Common/Models/ElementStatusModel.vb new file mode 100644 index 00000000..8132ef5e --- /dev/null +++ b/EnvelopeGenerator.Common/Models/ElementStatusModel.vb @@ -0,0 +1,81 @@ +Imports System.Data.SqlClient + +Public Class ElementStatusModel + Inherits BaseModel + + Public Sub New(pState As State) + MyBase.New(pState) + End Sub + + Public Function Insert(pElementStatus As ElementStatus) As Boolean + Try + Dim oSql = "INSERT INTO [dbo].[TBSIG_ELEMENT_STATUS] + ([ENVELOPE_ID] + ,[RECEIVER_ELEMENT_ID] + ,[STATUS] + ,[STATUS_CHANGED_WHEN] + ,[VALUE]) + VALUES + (@ENVELOPE_ID + ,@ELEMENT_ID + ,@STATUS + ,@STATUS_CHANGED_WHEN + ,@VALUE)" + + Dim oCommand As New SqlCommand(oSql) + oCommand.Parameters.Add("ENVELOPE_ID", SqlDbType.Int).Value = pElementStatus.EnvelopeId + oCommand.Parameters.Add("ELEMENT_ID", SqlDbType.Int).Value = pElementStatus.ElementId + oCommand.Parameters.Add("STATUS", SqlDbType.NVarChar).Value = pElementStatus.Status.ToString() + oCommand.Parameters.Add("STATUS_CHANGED_WHEN", SqlDbType.DateTime).Value = Now() + oCommand.Parameters.Add("VALUE", SqlDbType.NVarChar).Value = pElementStatus.ElementValue + + If Database.ExecuteNonQuery(oCommand) Then + pElementStatus.Id = GetElementId(pElementStatus) + Return True + Else + Return False + End If + Catch ex As Exception + Logger.Error(ex) + Return False + End Try + End Function + + Public Function Update(pElementStatus As ElementStatus) As Boolean + Try + Dim oSql = "UPDATE [dbo].[TBSIG_ELEMENT_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 = pElementStatus.Id + oCommand.Parameters.Add("STATUS", SqlDbType.NVarChar).Value = pElementStatus.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 = pElementStatus.ElementValue + + 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(pElement As ElementStatus) As Integer + Try + Return Database.GetScalarValue($"SELECT MAX(GUID) FROM TBSIG_ELEMENT_STATUS + WHERE ENVELOPE_ID = {pElement.EnvelopeId} AND RECEIVER_ELEMENT_ID = {pElement.ElementId}") + + Catch ex As Exception + Logger.Error(ex) + Return Nothing + End Try + End Function +End Class