Feat: Se añaden las capas de modelos y respositorios para el modulo de Suscripciones
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using Dapper;
|
||||
using GestionIntegral.Api.Models.Suscripciones;
|
||||
using System.Data;
|
||||
|
||||
namespace GestionIntegral.Api.Data.Repositories.Suscripciones
|
||||
{
|
||||
public class LoteDebitoRepository : ILoteDebitoRepository
|
||||
{
|
||||
private readonly DbConnectionFactory _connectionFactory;
|
||||
private readonly ILogger<LoteDebitoRepository> _logger;
|
||||
|
||||
public LoteDebitoRepository(DbConnectionFactory connectionFactory, ILogger<LoteDebitoRepository> logger)
|
||||
{
|
||||
_connectionFactory = connectionFactory;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<LoteDebito?> CreateAsync(LoteDebito nuevoLote, IDbTransaction transaction)
|
||||
{
|
||||
if (transaction == null || transaction.Connection == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(transaction), "La transacción o su conexión no pueden ser nulas.");
|
||||
}
|
||||
|
||||
const string sqlInsert = @"
|
||||
INSERT INTO dbo.susc_LotesDebito
|
||||
(FechaGeneracion, Periodo, NombreArchivo, ImporteTotal, CantidadRegistros, IdUsuarioGeneracion)
|
||||
OUTPUT INSERTED.*
|
||||
VALUES
|
||||
(GETDATE(), @Periodo, @NombreArchivo, @ImporteTotal, @CantidadRegistros, @IdUsuarioGeneracion);";
|
||||
|
||||
try
|
||||
{
|
||||
return await transaction.Connection.QuerySingleAsync<LoteDebito>(sqlInsert, nuevoLote, transaction);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al crear el registro de LoteDebito para el período {Periodo}", nuevoLote.Periodo);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user