SQL-Abfragen in Models verschoben
User Model neu
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
Imports System.Data.Common
|
||||
Imports System.Data.SqlClient
|
||||
Imports System.Data.SqlClient
|
||||
Imports System.IO
|
||||
Imports System.Runtime.Remoting.Messaging
|
||||
Imports DigitalData.Modules.Base
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports EnvelopeGenerator.Common
|
||||
Imports EnvelopeGenerator.Form.My.Resources
|
||||
Imports EnvelopeGenerator.Common.Constants
|
||||
|
||||
Public Class EnvelopeEditorController
|
||||
Inherits BaseClass
|
||||
@@ -18,6 +16,8 @@ Public Class EnvelopeEditorController
|
||||
Private DocumentModel As DocumentModel
|
||||
Private ReceiverModel As ReceiverModel
|
||||
Private ElementModel As ElementModel
|
||||
Private HistoryModel As HistoryModel
|
||||
Private UserModel As UserModel
|
||||
|
||||
Public ReadOnly Envelope As Envelope = Nothing
|
||||
|
||||
@@ -50,12 +50,26 @@ Public Class EnvelopeEditorController
|
||||
DocumentModel = New DocumentModel(pState)
|
||||
ReceiverModel = New ReceiverModel(pState)
|
||||
ElementModel = New ElementModel(pState)
|
||||
HistoryModel = New HistoryModel(pState)
|
||||
UserModel = New UserModel(pState)
|
||||
End Sub
|
||||
|
||||
#Region "Public"
|
||||
Public Function CreateEnvelope() As Envelope
|
||||
Dim oEnvelope As New Envelope() With {.UserId = State.UserId}
|
||||
Dim oEnvelope As New Envelope() With {
|
||||
.UserId = State.UserId,
|
||||
.User = UserModel.SelectUser()
|
||||
}
|
||||
If EnvelopeModel.Insert(oEnvelope) Then
|
||||
|
||||
Dim newHistoryEntry As New EnvelopeHistoryEntry With {
|
||||
.EnvelopeId = oEnvelope.Id,
|
||||
.Status = HistoryStatus.Created,
|
||||
.ActionTitle = "Envelope erzeugt",
|
||||
.ActionDescription = "Envelope wurde erzeugt",
|
||||
}
|
||||
'TODO .UserEmailAddress = oEnvelope.User.Email ' TODO - fehlt noch
|
||||
|
||||
Return oEnvelope
|
||||
Else
|
||||
Return Nothing
|
||||
@@ -182,7 +196,7 @@ Public Class EnvelopeEditorController
|
||||
Try
|
||||
Return pEnvelope.Documents.
|
||||
Where(Function(d) d.Id = 0).
|
||||
Select(Function(d) InsertDocument(pEnvelope, d, pTransaction)).
|
||||
Select(Function(d) DocumentModel.Insert(pEnvelope, d, pTransaction)).
|
||||
All(Function(pResult) pResult = True)
|
||||
|
||||
Catch ex As Exception
|
||||
@@ -191,30 +205,6 @@ Public Class EnvelopeEditorController
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function InsertDocument(pEnvelope As Envelope, pDocument As EnvelopeDocument, pTransaction As SqlTransaction) As Boolean
|
||||
Dim oSql = "INSERT INTO [dbo].[TBSIG_ENVELOPE_DOCUMENT]
|
||||
([FILENAME]
|
||||
,[FILEPATH]
|
||||
,[ENVELOPE_ID])
|
||||
VALUES
|
||||
(@FILENAME
|
||||
,@FILEPATH
|
||||
,@ENVELOPE_ID)"
|
||||
|
||||
Dim oCommand As New SqlCommand(oSql)
|
||||
oCommand.Parameters.Add("FILENAME", SqlDbType.NVarChar).Value = pDocument.Filename
|
||||
oCommand.Parameters.Add("FILEPATH", SqlDbType.NVarChar).Value = pDocument.Filepath
|
||||
oCommand.Parameters.Add("ENVELOPE_ID", SqlDbType.Int).Value = pEnvelope.Id
|
||||
|
||||
If Database.ExecuteNonQuery(oCommand, pTransaction) Then
|
||||
pDocument.EnvelopeId = pEnvelope.Id
|
||||
pDocument.Id = GetDocumentId(pDocument.Filename, pEnvelope, pTransaction)
|
||||
Return True
|
||||
Else
|
||||
Return False
|
||||
End If
|
||||
End Function
|
||||
|
||||
Private Function SaveEnvelopeReceivers(pEnvelope As Envelope, pTransaction As SqlTransaction) As Boolean
|
||||
Try
|
||||
If pEnvelope.Id = Nothing Then
|
||||
@@ -283,23 +273,4 @@ Public Class EnvelopeEditorController
|
||||
End If
|
||||
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
|
||||
|
||||
Private Function GetDocumentId(pFilename As String, pEnvelope As Envelope, pTransaction As SqlTransaction) As Integer
|
||||
Try
|
||||
Return Database.GetScalarValue($"SELECT MAX(GUID) FROM TBSIG_ENVELOPE_DOCUMENT WHERE FILENAME = '{pFilename}' AND ENVELOPE_ID = {pEnvelope.Id}", pTransaction)
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user