This commit is contained in:
2025-12-25 13:54:49 -06:00
parent d405b61ddd
commit 3457721238
26 changed files with 3509 additions and 139 deletions

View File

@@ -15,12 +15,6 @@ namespace MieSystem.Data.Repositories
_connectionFactory = databaseConnectionFactory;
}
/*public async Task<int> CreateAsync(Expediente expediente)
{
using var connection = await _connectionFactory.CreateConnectionAsync();
return await connection.InsertAsync(expediente);
}*/
public async Task<int> CreateAsync(Expediente expediente)
{
using var connection = await _connectionFactory.CreateConnectionAsync();
@@ -92,34 +86,27 @@ namespace MieSystem.Data.Repositories
return affected > 0;
}
public async Task<IEnumerable<Expediente?>> GetActivosAsync()
{
using var connection = await _connectionFactory.CreateConnectionAsync();
if (connection.State == System.Data.ConnectionState.Open)
{
var result = await connection.QueryAsync<Expediente?>(@"SELECT * FROM expedientes where activo = True ORDER BY nombre");
return result;
}
else
{
System.Diagnostics.Debug.WriteLine("Estado de la conexion es:" + connection.State);
return null;
}
}
public async Task<IEnumerable<Expediente?>> GetAllAsync()
{
using var connection = await _connectionFactory.CreateConnectionAsync();
if (connection.State == System.Data.ConnectionState.Open) {
/*var result = await connection.QueryAsync<Expediente>(
@"SELECT
id,
nombre,
apellidos,
fecha_nacimiento::timestamp as fecha_nacimiento, -- Convertir a timestamp
sexo,
nombre_padre,
nombre_madre,
nombre_responsable,
parentesco_responsable,
direccion,
telefono,
observaciones,
foto_url,
fecha_creacion,
fecha_actualizacion,
activo
FROM expedientes
ORDER BY nombre"
);*/
var result = await connection.QueryAsync<Expediente>(
@"SELECT *
FROM expedientes
@@ -148,8 +135,44 @@ namespace MieSystem.Data.Repositories
{
using var connection = await _connectionFactory.CreateConnectionAsync();
// Con Dapper.Contrib
return await connection.UpdateAsync(expediente);
var sql = @"
UPDATE expedientes SET
nombre = @Nombre,
apellidos = @Apellidos,
fecha_nacimiento = @FechaNacimiento,
sexo = @Sexo,
nombre_padre = @NombrePadre,
nombre_madre = @NombreMadre,
nombre_responsable = @NombreResponsable,
parentesco_responsable = @ParentescoResponsable,
direccion = @Direccion,
telefono = @Telefono,
observaciones = @Observaciones,
foto_url = @FotoUrl,
fecha_actualizacion = CURRENT_TIMESTAMP,
activo = @Activo
WHERE id = @Id";
var parameters = new
{
expediente.Id,
expediente.Nombre,
expediente.Apellidos,
FechaNacimiento = expediente.FechaNacimiento.Date, // Solo fecha
expediente.Sexo,
expediente.NombrePadre,
expediente.NombreMadre,
expediente.NombreResponsable,
expediente.ParentescoResponsable,
expediente.Direccion,
expediente.Telefono,
expediente.Observaciones,
expediente.FotoUrl,
expediente.Activo
};
var affectedRows = await connection.ExecuteAsync(sql, parameters);
return affectedRows > 0;
}
}
}