| | | 1 | | using FAU.Entidades; |
| | | 2 | | using Microsoft.EntityFrameworkCore; |
| | | 3 | | |
| | | 4 | | namespace FAU.DataAccess.Repositories; |
| | | 5 | | |
| | | 6 | | public class DocumentoRepository : IDocumentoRepository |
| | | 7 | | { |
| | | 8 | | private readonly ApplicationDbContext _context; |
| | | 9 | | |
| | 0 | 10 | | public DocumentoRepository(ApplicationDbContext context) => _context = context; |
| | | 11 | | |
| | | 12 | | public async Task<Documento?> GetByIdAsync(long id) => |
| | 0 | 13 | | await _context.Documentos.FindAsync(id); |
| | | 14 | | |
| | | 15 | | public async Task<IEnumerable<Documento>> GetByTipoEntidadAsync(string tipo, long entidadId) => |
| | 0 | 16 | | await _context.Documentos |
| | 0 | 17 | | .Where(d => d.Tipo == tipo && d.EntidadId == entidadId) |
| | 0 | 18 | | .OrderByDescending(d => d.FechaCarga) |
| | 0 | 19 | | .ToListAsync(); |
| | | 20 | | |
| | | 21 | | public async Task<Documento> CreateAsync(Documento documento) |
| | | 22 | | { |
| | 0 | 23 | | _context.Documentos.Add(documento); |
| | 0 | 24 | | await _context.SaveChangesAsync(); |
| | 0 | 25 | | return documento; |
| | 0 | 26 | | } |
| | | 27 | | |
| | | 28 | | public async Task DeleteAsync(long id) |
| | | 29 | | { |
| | 0 | 30 | | var d = await _context.Documentos.FindAsync(id); |
| | 0 | 31 | | if (d != null) |
| | | 32 | | { |
| | 0 | 33 | | _context.Documentos.Remove(d); |
| | 0 | 34 | | await _context.SaveChangesAsync(); |
| | | 35 | | } |
| | 0 | 36 | | } |
| | | 37 | | } |