Developer 02 7b7a4b4f65 Add AddEnvelopeReceiver method and SQL class
Introduces the `AddEnvelopeReceiver` method in the `Extension` class to add envelope receivers with parameters for UUID, email, salutation, and optional phone.

Also adds the `EnvelopeReceiverAddReadSQL` class implementing `ISQL<Envelope>`, containing a SQL query to create a new receiver using the stored procedure `PRSIG_API_CREATE_RECEIVER`.

Includes XML documentation for improved code readability and maintainability.
2025-05-06 09:50:20 +02:00

80 lines
3.1 KiB
C#

using Dapper;
using EnvelopeGenerator.Application.SQL;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Contracts.SQLExecutor;
/// <summary>
///
/// </summary>
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;
}
/// <summary>
///
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="executor"></param>
/// <param name="userId"></param>
/// <param name="title"></param>
/// <param name="message"></param>
/// <param name="tfaEnabled"></param>
/// <param name="cancellation"></param>
/// <returns></returns>
public static async Task<TEntity?> CreateEnvelopeAsync<TEntity>(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<TEntity, EnvelopeCreateReadSQL>(parameters, cancellation);
return envelopes.FirstOrDefault();
}
/// <summary>
///
/// </summary>
/// <param name="executor"></param>
/// <param name="userId"></param>
/// <param name="title"></param>
/// <param name="message"></param>
/// <param name="tfaEnabled"></param>
/// <param name="cancellation"></param>
/// <returns></returns>
public static async Task<Envelope?> 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);
}
/// <summary>
///
/// </summary>
/// <param name="executor"></param>
/// <param name="envelope_uuid"></param>
/// <param name="emailAdress"></param>
/// <param name="salutation"></param>
/// <param name="phone"></param>
/// <param name="cancellation"></param>
/// <returns></returns>
public static async Task<EnvelopeReceiver?> 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<EnvelopeReceiver, EnvelopeReceiverAddReadSQL>(parameters, cancellation);
return envelopeReceivers.FirstOrDefault();
}
}