Refactor SQL execution in DocumentCreateReadSQL

Changed namespace for DocumentCreateReadSQL and updated SQL command to use formatted strings for parameters. Simplified DocumentExecutor to directly use the formatted SQL, enhancing clarity and reducing complexity in parameter handling.
This commit is contained in:
Developer 02 2025-05-07 13:21:17 +02:00
parent a781440252
commit ad855b77cd
2 changed files with 5 additions and 5 deletions

View File

@ -10,17 +10,17 @@ namespace EnvelopeGenerator.Application.SQL;
public class DocumentCreateReadSQL : ISQL<EnvelopeDocument>
{
/// <summary>
///
/// Base64, OUT_UID
/// </summary>
public string Raw => @"
USE [DD_ECM]
DECLARE @BYTE_DATA1 as VARBINARY(MAX)
SET @BYTE_DATA1 = CONVERT(VARBINARY(MAX),'@Base64')
SET @BYTE_DATA1 = CONVERT(VARBINARY(MAX),{0})
DECLARE @OUT_DOCID int
EXEC [dbo].[PRSIG_API_ADD_DOC]
@ENV_UID = @OUT_UID,
@ENV_UID = {1},
@BYTE_DATA = @BYTE_DATA1,
@OUT_DOCID = @OUT_DOCID OUTPUT

View File

@ -18,9 +18,9 @@ public class DocumentExecutor : SQLExecutor, IDocumentExecutor
{
using var connection = new SqlConnection(Params.ConnectionString);
var sql = Provider.GetRequiredService<DocumentCreateReadSQL>();
var formattedSql = string.Format(sql.Raw, base64, envelope_uuid);
await connection.OpenAsync(cancellation);
var parameters = DocumentCreateReadSQL.CreateParmas(base64, envelope_uuid);
var documents = await connection.QueryAsync<EnvelopeDocument>(sql.Raw, parameters);
var documents = await connection.QueryAsync<EnvelopeDocument>(formattedSql);
return documents.FirstOrDefault()
?? throw new InvalidOperationException($"Document creation failed. Parameters:" +
$"base64={base64}, envelope_uuid='{envelope_uuid}'.");