43 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
		
		
			
		
	
	
			43 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
|  | 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; | ||
|  |             } | ||
|  |         } | ||
|  |     } | ||
|  | } |