Files
foundation_system/foundation_system/Services/AntecedentesService.cs
2025-12-30 18:12:13 -06:00

38 lines
945 B
C#

using foundation_system.Data;
using foundation_system.Models;
using Microsoft.EntityFrameworkCore;
namespace foundation_system.Services;
public class AntecedentesService : IAntecedentesService
{
private readonly ApplicationDbContext _context;
public AntecedentesService(ApplicationDbContext context)
{
_context = context;
}
public async Task<List<AntecedenteNino>> GetHistorialByNinoIdAsync(long ninoId)
{
return await _context.AntecedentesNino
.Where(a => a.NinoId == ninoId && a.Activo)
.OrderByDescending(a => a.FechaIncidente)
.ToListAsync();
}
public async Task<bool> AddAntecedenteAsync(AntecedenteNino antecedente)
{
try
{
_context.AntecedentesNino.Add(antecedente);
await _context.SaveChangesAsync();
return true;
}
catch
{
return false;
}
}
}