Integracion_DGA/DAL/JobsDgaRepository.cs

75 lines
2.8 KiB
C#
Raw Normal View History

using System.Data;
using Dapper;
using Microsoft.Data.SqlClient;
using Microsoft.Identity.Client;
using Shared.DTO.Integracion_DGA;
2025-07-01 09:59:59 -04:00
using Shared.DTO.VariablesEntorno;
namespace DAL
{
public class JobsDgaRepository
{
2025-07-15 10:53:56 -04:00
public async Task<bool> SpRegistrarMedicionesDga()
{
try
{
2025-07-01 09:59:59 -04:00
using (var connection = new SqlConnection(BdConexion.StringConnection))
{
await connection.OpenAsync();
// Ejecuta el stored procedure sin parámetros
2025-07-15 10:53:56 -04:00
await connection.ExecuteAsync("SP_REGISTRAR_DATOS_DGA", commandType: CommandType.StoredProcedure);
}
return true; // Éxito
}
catch (Exception ex)
{
throw new Exception($"Error: {ex.Message}");
}
}
2025-07-14 09:48:59 -04:00
public async Task<bool> InsertarDgaCaudal(List<DGAInsert> dgaMacroResultados)
{
try
{
using (SqlConnection connection = new SqlConnection(BdConexion.StringConnection))
{
await connection.OpenAsync();
// 1. Truncar la tabla antes de insertar
await connection.ExecuteAsync("TRUNCATE TABLE DGA_CAUDAL");
// 2. Insertar la lista de registros
string sql = "INSERT INTO DGA_CAUDAL (TAG, CAUDAL, FECHAMEDICION) VALUES (@TAG, @VALOR, @FECHAMEDICION)";
// Esto inserta todos los elementos de la lista en la tabla
await connection.ExecuteAsync(sql, dgaMacroResultados);
return true;
}
}
catch (Exception ex)
{
throw new Exception($"Error: {ex.Message}");
}
}
public async Task<bool> InsertarDgaNivel(List<DGAInsert> dgaMacroResultados)
{
try
{
using (SqlConnection connection = new SqlConnection(BdConexion.StringConnection))
{
await connection.OpenAsync();
// 1. Truncar la tabla antes de insertar
await connection.ExecuteAsync("TRUNCATE TABLE DGA_NIVEL");
// 2. Insertar la lista de registros
string sql = "INSERT INTO DGA_NIVEL (TAG, NIVEL_FREATICO, FECHAMEDICION) VALUES (@TAG, @VALOR, @FECHAMEDICION)";
// Esto inserta todos los elementos de la lista en la tabla
await connection.ExecuteAsync(sql, dgaMacroResultados);
return true;
}
}
catch (Exception ex)
{
throw new Exception($"Error: {ex.Message}");
}
}
}
}