Integracion_DGA/DAL/LogMedicionScadaRepository.cs

38 lines
1.3 KiB
C#
Raw Normal View History

using Dapper;
using Microsoft.Data.SqlClient;
using Shared.DTO.Envios_DGA;
2025-07-01 09:59:59 -04:00
using Shared.DTO.VariablesEntorno;
namespace DAL
{
public class LogMedicionScadaRepository
{
public async Task<bool> InsertarLogMedicionScadaAsync(LogMedicionScada logMedicionScada)
{
try
{
2025-07-01 09:59:59 -04:00
using (var connection = new SqlConnection(BdConexion.StringConnection))
{
await connection.OpenAsync();
// Truncar la tabla antes de insertar
await connection.ExecuteAsync("TRUNCATE TABLE DGA_LOGS_OPERACION");
// Insertar todos los datos de la lista usando Dapper
var sql = @"INSERT INTO dbo.DGA_LOGS_OPERACION
(estado_envio, json_enviado, json_recibido, comprobante, fecha_envio, id_medicion_smartscada_operacion)
VALUES
(@EstadoEnvio, @JsonEnviado, @JsonRecibido, @Comprobante, @FechaEnvio, @IdMedicionSmartscadaOperacion)";
await connection.ExecuteAsync(sql, logMedicionScada);
return true; // Éxito
}
}
catch (Exception ex)
{
throw new Exception($"Error: {ex.Message}");
}
}
}
}