74 lines
2.8 KiB
C#
74 lines
2.8 KiB
C#
using System.Data;
|
|
using Dapper;
|
|
using Microsoft.Data.SqlClient;
|
|
using Microsoft.Identity.Client;
|
|
using Shared.DTO.Integracion_DGA;
|
|
using Shared.DTO.VariablesEntorno;
|
|
|
|
namespace DAL
|
|
{
|
|
public class JobsDgaRepository
|
|
{
|
|
public async Task<bool> SpRegistrarMedicionesDga()
|
|
{
|
|
try
|
|
{
|
|
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
|
{
|
|
await connection.OpenAsync();
|
|
// Ejecuta el stored procedure sin parámetros
|
|
await connection.ExecuteAsync("SP_REGISTRAR_DATOS_DGA", commandType: CommandType.StoredProcedure);
|
|
}
|
|
return true; // Éxito
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception($"Error: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
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}");
|
|
}
|
|
}
|
|
}
|
|
}
|