29 lines
900 B
C#
29 lines
900 B
C#
|
|
using Dapper;
|
||
|
|
using Inventario.API.Data;
|
||
|
|
using Inventario.API.Models;
|
||
|
|
|
||
|
|
namespace Inventario.API.Helpers
|
||
|
|
{
|
||
|
|
public static class HistorialHelper
|
||
|
|
{
|
||
|
|
public static async Task RegistrarCambios(DapperContext context, int equipoId, Dictionary<string, (string anterior, string nuevo)> cambios)
|
||
|
|
{
|
||
|
|
var query = @"INSERT INTO dbo.historial_equipos (equipo_id, campo_modificado, valor_anterior, valor_nuevo)
|
||
|
|
VALUES (@EquipoId, @CampoModificado, @ValorAnterior, @ValorNuevo);";
|
||
|
|
|
||
|
|
using (var connection = context.CreateConnection())
|
||
|
|
{
|
||
|
|
foreach (var cambio in cambios)
|
||
|
|
{
|
||
|
|
await connection.ExecuteAsync(query, new
|
||
|
|
{
|
||
|
|
EquipoId = equipoId,
|
||
|
|
CampoModificado = cambio.Key,
|
||
|
|
ValorAnterior = cambio.Value.anterior,
|
||
|
|
ValorNuevo = cambio.Value.nuevo
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|