diff --git a/EnvelopeGenerator.Application/SQL/EnvelopeCreateReadSQL.cs b/EnvelopeGenerator.Application/SQL/EnvelopeCreateReadSQL.cs index 449eb9d2..40b05e68 100644 --- a/EnvelopeGenerator.Application/SQL/EnvelopeCreateReadSQL.cs +++ b/EnvelopeGenerator.Application/SQL/EnvelopeCreateReadSQL.cs @@ -1,6 +1,7 @@ using Dapper; using EnvelopeGenerator.Application.Contracts.SQLExecutor; using EnvelopeGenerator.Domain.Entities; +using System.Data; namespace EnvelopeGenerator.Application.SQL; @@ -10,18 +11,17 @@ namespace EnvelopeGenerator.Application.SQL; public class EnvelopeCreateReadSQL : ISQL { /// - /// + /// USER_ID, TITLE, TFAEnabled, MESSAGE /// public string Raw => @" - USE [DD_ECM]; DECLARE @OUT_UID varchar(36); EXEC [dbo].[PRSIG_API_CREATE_ENVELOPE] - @USER_ID = @UserId, - @TITLE = @Title, - @TFAEnabled = @TfaEnabled, - @MESSAGE = @Message, - @OUT_UID = @OUT_UID OUTPUT; + {0}, + {1}, + {2}, + {3}, + @OUT_UID OUTPUT; SELECT TOP(1) * FROM [dbo].[TBSIG_ENVELOPE] @@ -36,13 +36,14 @@ public class EnvelopeCreateReadSQL : ISQL /// /// /// - public static DynamicParameters CreateParmas(int userId, string title = "", string message = "", bool tfaEnabled = false) + public static DynamicParameters CreateParams(int userId, string title = "", string message = "", bool tfaEnabled = false) { var parameters = new DynamicParameters(); parameters.Add("@UserId", userId); parameters.Add("@Title", title); parameters.Add("@TfaEnabled", tfaEnabled ? 1 : 0); parameters.Add("@Message", message); + parameters.Add("@OutUid", dbType: DbType.String, size: 36, direction: ParameterDirection.Output); return parameters; } } \ No newline at end of file diff --git a/EnvelopeGenerator.Application/SQL/EnvelopeReceiverAddReadSQL.cs b/EnvelopeGenerator.Application/SQL/EnvelopeReceiverAddReadSQL.cs index c065accd..1c499858 100644 --- a/EnvelopeGenerator.Application/SQL/EnvelopeReceiverAddReadSQL.cs +++ b/EnvelopeGenerator.Application/SQL/EnvelopeReceiverAddReadSQL.cs @@ -10,16 +10,16 @@ namespace EnvelopeGenerator.Application.SQL; public class EnvelopeReceiverAddReadSQL : ISQL { /// - /// + /// ENV_UID, EMAIL_ADRESS, SALUTATION, PHONE, /// public string Raw => @" DECLARE @OUT_RECEIVER_ID int EXEC [dbo].[PRSIG_API_CREATE_RECEIVER] - @ENV_UID, - @EMAIL_ADRESS, - @SALUTATION, - @PHONE, + {0}, + {1}, + {2}, + {3}, @OUT_RECEIVER_ID OUTPUT SELECT TOP(1) * diff --git a/EnvelopeGenerator.Application/SQL/ParamsExtensions.cs b/EnvelopeGenerator.Application/SQL/ParamsExtensions.cs new file mode 100644 index 00000000..2558eb5e --- /dev/null +++ b/EnvelopeGenerator.Application/SQL/ParamsExtensions.cs @@ -0,0 +1,28 @@ +namespace EnvelopeGenerator.Application.SQL; + +/// +/// Extension method for converting objects to SQL parameter strings. +/// +public static class ParamsExtensions +{ + /// + /// Converts a .NET object to its corresponding SQL-safe parameter string. + /// + /// The object to convert. + /// A string representing the SQL parameter. + public static string ToSqlParam(this object? obj) + { + if (obj is null) + return "NULL"; + else if (obj is string strVal) + return $"'{strVal}'"; + else if (obj is bool boolVal) + return boolVal ? "1" : "0"; + else if (obj is double doubleVal) + return $"'{doubleVal}'"; + else if (obj is int intVal) + return intVal.ToString(); + else + throw new NotSupportedException($"Type '{obj.GetType().FullName}' is not supported for SQL parameter conversion."); + } +}