Add documentstatus

This commit is contained in:
Jonathan Jenne
2023-10-11 11:10:38 +02:00
parent df3e01b921
commit 8d5e24c6a7
6 changed files with 145 additions and 19 deletions

View File

@@ -14,6 +14,11 @@
Created = 0
End Enum
Public Enum DocumentStatus
Created = 0
Signed = 1
End Enum
Public Enum EnvelopeHistoryActionType
Created = 0
Saved = 1

View File

@@ -0,0 +1,10 @@
Public Class DocumentStatus
Public Property Id As Integer
Public Property EnvelopeId As Integer
Public Property ReceiverId As Integer
Public Property Value As String
Public Property Status As Constants.DocumentStatus = Constants.DocumentStatus.Created
Public Property StatusChangedWhen As Date
End Class

View File

@@ -95,6 +95,7 @@
<Compile Include="Constants.vb" />
<Compile Include="Entities\DbConfig.vb" />
<Compile Include="Entities\ElementMetadata.vb" />
<Compile Include="Entities\DocumentStatus.vb" />
<Compile Include="Entities\ElementStatus.vb" />
<Compile Include="Entities\EmailData.vb" />
<Compile Include="Entities\EmailTemplate.vb" />
@@ -112,6 +113,7 @@
<Compile Include="Models\ConfigModel.vb" />
<Compile Include="Models\DocumentModel.vb" />
<Compile Include="Models\ElementModel.vb" />
<Compile Include="Models\DocumentStatusModel.vb" />
<Compile Include="Models\ElementStatusModel.vb" />
<Compile Include="Models\EmailModel.vb" />
<Compile Include="Models\EnvelopeModel.vb" />

View 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

View File

@@ -1,4 +1,5 @@
using DigitalData.Modules.Logging;
using DigitalData.Modules.Database;
using DigitalData.Modules.Logging;
using EnvelopeGenerator.Common;
using EnvelopeGenerator.Common.My.Resources;
using EnvelopeGenerator.Web.Services;
@@ -9,7 +10,7 @@ using System.Text;
namespace EnvelopeGenerator.Web.Handler
{
public class FileHandler
public class FileHandler
{
/// <summary>
/// URL: GET /api/envelope/{envelopeKey}
@@ -17,7 +18,7 @@ namespace EnvelopeGenerator.Web.Handler
/// Returns a
/// </summary>
/// <returns></returns>
public static IResult HandleGetEnvelope(HttpContext ctx, DatabaseService database, LoggingService logging)
public IResult HandleGetEnvelope(HttpContext ctx, DatabaseService database, LoggingService logging)
{
var logger = logging.LogConfig.GetLogger("FileHandler");
@@ -48,7 +49,7 @@ namespace EnvelopeGenerator.Web.Handler
/// Returns a document for the supplied EnvelopeKey and Document Id / Index
/// </summary>
/// <returns>file buffer of the requested document</returns>
public async static Task<IResult> HandleGetDocument(HttpContext ctx, DatabaseService database, LoggingService logging)
public async Task<IResult> HandleGetDocument(HttpContext ctx, DatabaseService database, LoggingService logging)
{
var logger = logging.LogConfig.GetLogger("FileHandler");
@@ -80,7 +81,7 @@ namespace EnvelopeGenerator.Web.Handler
}
}
public async static Task<IResult> HandlePostDocument(HttpContext ctx, DatabaseService database, LoggingService logging)
public async Task<IResult> HandlePostDocument(HttpContext ctx, DatabaseService database, LoggingService logging)
{
var logger = logging.LogConfig.GetLogger("FileHandler");
@@ -113,7 +114,7 @@ namespace EnvelopeGenerator.Web.Handler
public async static Task<IResult> HandlePostEnvelope(HttpContext ctx, DatabaseService database, LoggingService logging)
public async Task<IResult> HandlePostEnvelope(HttpContext ctx, DatabaseService database, LoggingService logging)
{
var logger = logging.LogConfig.GetLogger("FileHandler");
@@ -129,14 +130,23 @@ namespace EnvelopeGenerator.Web.Handler
int documentId = EnsureValidDocumentIndex(logger, ctx.Request);
var document = GetDocument(r.Envelope, documentId);
var annotationData = EnsureValidAnnotationData(logger, ctx.Request);
string? annotationData = await EnsureValidAnnotationData(logger, ctx.Request);
if (annotationData == null)
{
throw new ArgumentNullException("AnnotationData");
}
// TODO: Save annotations to database
State state = GetState(logging.LogConfig, database.MSSQL);
DocumentStatusModel model = new(state);
model.InsertOrUpdate(new DocumentStatus()
{
EnvelopeId = r.Envelope.Id,
ReceiverId = r.ReceiverId,
Value = annotationData,
Status = Common.Constants.DocumentStatus.Signed
});
return Results.Ok();
}
@@ -145,12 +155,19 @@ namespace EnvelopeGenerator.Web.Handler
// Better error handling & reporting
logger.Error(e);
return Results.Problem();
}
}
}
private static int EnsureValidDocumentIndex(Logger logger, HttpRequest request)
private State GetState(LogConfig LogConfig, MSSQLServer Database)
{
return new State
{
LogConfig = LogConfig,
Database = Database,
};
}
private int EnsureValidDocumentIndex(Logger logger, HttpRequest request)
{
if (request.Query.TryGetValue("index", out StringValues documentIndexString))
{
@@ -169,7 +186,7 @@ namespace EnvelopeGenerator.Web.Handler
}
}
private static string EnsureValidEnvelopeKey(Logger logger, HttpRequest request)
private string EnsureValidEnvelopeKey(Logger logger, HttpRequest request)
{
logger.Debug("Parsing EnvelopeKey..");
var envelopeKey = request.RouteValues["envelopeKey"] as string;
@@ -190,7 +207,7 @@ namespace EnvelopeGenerator.Web.Handler
return envelopeKey;
}
private static async Task<string> EnsureValidAnnotationData(Logger logger, HttpRequest request)
private async Task<string?> EnsureValidAnnotationData(Logger logger, HttpRequest request)
{
logger.Debug("Parsing AnnotationData..");
@@ -210,7 +227,7 @@ namespace EnvelopeGenerator.Web.Handler
}
private static EnvelopeDocument GetDocument(Common.Envelope envelope, int documentId)
private EnvelopeDocument GetDocument(Common.Envelope envelope, int documentId)
{
var document = envelope.Documents.
Where(d => d.Id == documentId).

View File

@@ -1,5 +1,6 @@
using EnvelopeGenerator.Web.Handler;
using EnvelopeGenerator.Web.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
@@ -35,10 +36,12 @@ app.UseStaticFiles();
app.UseRouting();
// Add file download endpoint
app.MapGet("/api/document/{envelopeKey}", FileHandler.HandleGetDocument);
app.MapPost("/api/document/{envelopeKey}", FileHandler.HandlePostDocument);
app.MapGet("/api/envelope/{envelopeKey}", FileHandler.HandleGetEnvelope);
app.MapPost("/api/envelope/{envelopeKey}", FileHandler.HandlePostEnvelope);
FileHandler handler = new();
app.MapGet("/api/document/{envelopeKey}", handler.HandleGetDocument);
app.MapPost("/api/document/{envelopeKey}", handler.HandlePostDocument);
app.MapGet("/api/envelope/{envelopeKey}", handler.HandleGetEnvelope);
app.MapPost("/api/envelope/{envelopeKey}", handler.HandlePostEnvelope);
// Blazor plumbing
app.MapBlazorHub();