| | | 1 | | using FAU.Entidades; |
| | | 2 | | using Microsoft.EntityFrameworkCore; |
| | | 3 | | |
| | | 4 | | namespace FAU.DataAccess.Repositories; |
| | | 5 | | |
| | | 6 | | public class EscalafonRepository : IEscalafonRepository |
| | | 7 | | { |
| | | 8 | | private readonly ApplicationDbContext _context; |
| | | 9 | | |
| | 8 | 10 | | public EscalafonRepository(ApplicationDbContext context) |
| | | 11 | | { |
| | 8 | 12 | | _context = context; |
| | 8 | 13 | | } |
| | | 14 | | |
| | | 15 | | public async Task<IEnumerable<Escalafon>> ObtenerTodosAsync() |
| | | 16 | | { |
| | 1 | 17 | | return await _context.Escalafones |
| | 1 | 18 | | .Where(e => e.Vigente) |
| | 1 | 19 | | .OrderBy(e => e.Denominacion) |
| | 1 | 20 | | .ToListAsync(); |
| | 1 | 21 | | } |
| | | 22 | | |
| | | 23 | | public async Task<Escalafon?> ObtenerPorIdAsync(long id) |
| | | 24 | | { |
| | 3 | 25 | | return await _context.Escalafones.FirstOrDefaultAsync(e => e.Id == id); |
| | 3 | 26 | | } |
| | | 27 | | |
| | | 28 | | public async Task<Escalafon> CrearAsync(Escalafon escalafon) |
| | | 29 | | { |
| | 7 | 30 | | _context.Escalafones.Add(escalafon); |
| | 7 | 31 | | await _context.SaveChangesAsync(); |
| | 7 | 32 | | return escalafon; |
| | 7 | 33 | | } |
| | | 34 | | |
| | | 35 | | public async Task<Escalafon> ActualizarAsync(Escalafon escalafon) |
| | | 36 | | { |
| | 1 | 37 | | _context.Escalafones.Update(escalafon); |
| | 1 | 38 | | await _context.SaveChangesAsync(); |
| | 1 | 39 | | return escalafon; |
| | 1 | 40 | | } |
| | | 41 | | |
| | | 42 | | public async Task<bool> ExisteCodigoAsync(string codigo) |
| | | 43 | | { |
| | 2 | 44 | | return await _context.Escalafones.AnyAsync(e => e.Codigo == codigo); |
| | 2 | 45 | | } |
| | | 46 | | |
| | | 47 | | public async Task<bool> ExistePorIdAsync(long id) |
| | | 48 | | { |
| | 1 | 49 | | return await _context.Escalafones.AnyAsync(e => e.Id == id); |
| | 1 | 50 | | } |
| | | 51 | | } |