diff --git a/EnvelopeGenerator.Application/Contracts/SQLExecutor/Extension.cs b/EnvelopeGenerator.Application/Contracts/SQLExecutor/Extension.cs new file mode 100644 index 00000000..a765a090 --- /dev/null +++ b/EnvelopeGenerator.Application/Contracts/SQLExecutor/Extension.cs @@ -0,0 +1,58 @@ +using Dapper; +using EnvelopeGenerator.Application.SQL; +using EnvelopeGenerator.Domain.Entities; + +namespace EnvelopeGenerator.Application.Contracts.SQLExecutor; + +/// +/// +/// +public static class Extension +{ + private static DynamicParameters CreateParmas(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); + return parameters; + } + + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public static async Task CreateEnvelopeAsync(this ISQLExecutor executor, int userId, string title = "", string message = "", bool tfaEnabled = false, CancellationToken cancellation = default) + where TEntity : class + { + var parameters = CreateParmas(userId, title, message, tfaEnabled); + + var envelopes = await executor.Execute(parameters, cancellation); + return envelopes.FirstOrDefault(); + } + + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public static async Task CreateEnvelopeAsync(this IEnvelopeExecutor executor, int userId, string title = "", string message = "", bool tfaEnabled = false, CancellationToken cancellation = default) + { + var parameters = CreateParmas(userId, title, message, tfaEnabled); + + return await executor.CreateEnvelopeAsync(parameters, cancellation: cancellation); + } +} \ No newline at end of file diff --git a/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeCommandHandler.cs b/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeCommandHandler.cs index a4b7d698..5c8cb3e9 100644 --- a/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeCommandHandler.cs +++ b/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeCommandHandler.cs @@ -1,6 +1,5 @@ using AutoMapper; using EnvelopeGenerator.Application.Contracts.SQLExecutor; -using EnvelopeGenerator.Application.SQL; using MediatR; namespace EnvelopeGenerator.Application.Envelopes.Commands; diff --git a/EnvelopeGenerator.Application/SQL/EnvelopeCreateReadSQL.cs b/EnvelopeGenerator.Application/SQL/EnvelopeCreateReadSQL.cs index 005932f6..9dc83fde 100644 --- a/EnvelopeGenerator.Application/SQL/EnvelopeCreateReadSQL.cs +++ b/EnvelopeGenerator.Application/SQL/EnvelopeCreateReadSQL.cs @@ -1,5 +1,4 @@ -using Dapper; -using EnvelopeGenerator.Application.Contracts.SQLExecutor; +using EnvelopeGenerator.Application.Contracts.SQLExecutor; using EnvelopeGenerator.Domain.Entities; namespace EnvelopeGenerator.Application.SQL; @@ -27,57 +26,4 @@ public class EnvelopeCreateReadSQL : ISQL FROM [dbo].[TBSIG_ENVELOPE] WHERE [ENVELOPE_UUID] = @OUT_UID; "; -} - -/// -/// -/// -public static class Extension -{ - private static DynamicParameters CreateParmas(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); - return parameters; - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static async Task CreateEnvelopeAsync(this ISQLExecutor executor, int userId, string title = "", string message = "", bool tfaEnabled = false, CancellationToken cancellation = default) - where TEntity : class - { - var parameters = CreateParmas(userId, title, message, tfaEnabled); - - var envelopes = await executor.Execute(parameters, cancellation); - return envelopes.FirstOrDefault(); - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static async Task CreateEnvelopeAsync(this IEnvelopeExecutor executor, int userId, string title = "", string message = "", bool tfaEnabled = false, CancellationToken cancellation = default) - { - var parameters = CreateParmas(userId, title, message, tfaEnabled); - - return await executor.CreateEnvelopeAsync(parameters, cancellation: cancellation); - } } \ No newline at end of file