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); } /// /// /// /// /// /// /// /// /// /// public static async Task AddEnvelopeReceiver(this ISQLExecutor executor, string envelope_uuid, string emailAdress, string salutation, string? phone = null, CancellationToken cancellation = default) { var parameters = new DynamicParameters(); parameters.Add("@ENV_UID", envelope_uuid); parameters.Add("@EMAIL_ADRESS", emailAdress); parameters.Add("@SALUTATION", salutation); parameters.Add("@PHONE", phone); var envelopeReceivers = await executor.Execute(parameters, cancellation); return envelopeReceivers.FirstOrDefault(); } }