< Summary

Information
Class: FAU.DataAccess.Repositories.PersonalRepository
Assembly: FAU.DataAccess
File(s): /home/runner/work/Sistema.Liquidacion.BE/Sistema.Liquidacion.BE/FAU.DataAccess/Repositories/PersonalRepository.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 104
Coverable lines: 104
Total lines: 160
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
GetAllAsync()100%210%
GetByIdAsync()100%210%
GetActivoByPersonaIdAsync()100%210%
GetByCedulaAsync()100%210%
GetByGradoIdAsync()100%210%
GetActivosAsync()100%210%
ExisteByCedulaAsync()100%210%
CreateAsync()0%620%
UpdateAsync()0%620%
DarBajaAsync()0%620%
CrearMovimientoAsync()0%620%

File(s)

/home/runner/work/Sistema.Liquidacion.BE/Sistema.Liquidacion.BE/FAU.DataAccess/Repositories/PersonalRepository.cs

#LineLine coverage
 1using FAU.Entidades;
 2using Microsoft.EntityFrameworkCore;
 3
 4namespace FAU.DataAccess.Repositories;
 5
 6/// <summary>
 7/// Repositorio de Personal (Relaciones Laborales)
 8/// </summary>
 9public class PersonalRepository : IPersonalRepository
 10{
 11    private readonly ApplicationDbContext _context;
 12
 013    public PersonalRepository(ApplicationDbContext context)
 14    {
 015        _context = context;
 016    }
 17
 18    public async Task<IEnumerable<RelacionLaboral>> GetAllAsync()
 19    {
 020        return await _context.RelacionesLaborales
 021            .Include(rl => rl.Persona)
 022            .Include(rl => rl.Grado)
 023            .Include(rl => rl.Escalafon)
 024            .Include(rl => rl.Situacion)
 025            .Include(rl => rl.Programa)
 026            .Include(rl => rl.Unidad)
 027            .Include(rl => rl.Compania)
 028            .Include(rl => rl.Regimen)
 029            .OrderByDescending(rl => rl.FechaInicio)
 030            .ToListAsync();
 031    }
 32
 33    public async Task<RelacionLaboral?> GetByIdAsync(long id)
 34    {
 035        return await _context.RelacionesLaborales
 036            .Include(rl => rl.Persona)
 037            .Include(rl => rl.Grado)
 038                .ThenInclude(g => g.Escalafon)
 039            .Include(rl => rl.Situacion)
 040            .Include(rl => rl.Programa)
 041            .Include(rl => rl.Unidad)
 042            .Include(rl => rl.Compania)
 043            .Include(rl => rl.Regimen)
 044            .Include(rl => rl.MovimientosLaborales)
 045                .ThenInclude(ml => ml.TipoMovimiento)
 046            .FirstOrDefaultAsync(rl => rl.Id == id);
 047    }
 48
 49    public async Task<RelacionLaboral?> GetActivoByPersonaIdAsync(long personaId)
 50    {
 051        return await _context.RelacionesLaborales
 052            .Include(rl => rl.Persona)
 053            .Include(rl => rl.Grado)
 054            .Include(rl => rl.Escalafon)
 055            .Include(rl => rl.Situacion)
 056            .Include(rl => rl.Programa)
 057            .Include(rl => rl.Unidad)
 058            .Include(rl => rl.Compania)
 059            .Include(rl => rl.Regimen)
 060            .FirstOrDefaultAsync(rl => rl.PersonaId == personaId && rl.Estado == "activo");
 061    }
 62
 63    public async Task<RelacionLaboral?> GetByCedulaAsync(string cedula)
 64    {
 065        return await _context.RelacionesLaborales
 066            .Include(rl => rl.Persona)
 067            .Include(rl => rl.Grado)
 068            .Include(rl => rl.Escalafon)
 069            .Include(rl => rl.Situacion)
 070            .Include(rl => rl.Programa)
 071            .Include(rl => rl.Unidad)
 072            .Include(rl => rl.Compania)
 073            .Include(rl => rl.Regimen)
 074            .FirstOrDefaultAsync(rl => rl.Persona.Cedula == cedula && rl.Estado == "activo");
 075    }
 76
 77    public async Task<IEnumerable<RelacionLaboral>> GetByGradoIdAsync(long gradoId)
 78    {
 079        return await _context.RelacionesLaborales
 080            .Include(rl => rl.Persona)
 081            .Include(rl => rl.Grado)
 082            .Include(rl => rl.Escalafon)
 083            .Include(rl => rl.Situacion)
 084            .Where(rl => rl.GradoId == gradoId && rl.Estado == "activo")
 085            .OrderBy(rl => rl.Persona.PrimerApellido)
 086            .ThenBy(rl => rl.Persona.PrimerNombre)
 087            .ToListAsync();
 088    }
 89
 90    public async Task<IEnumerable<RelacionLaboral>> GetActivosAsync()
 91    {
 092        return await _context.RelacionesLaborales
 093            .Include(rl => rl.Persona)
 094            .Include(rl => rl.Grado)
 095            .Include(rl => rl.Escalafon)
 096            .Include(rl => rl.Situacion)
 097            .Include(rl => rl.Programa)
 098            .Include(rl => rl.Unidad)
 099            .Include(rl => rl.Compania)
 0100            .Where(rl => rl.Estado == "activo")
 0101            .OrderBy(rl => rl.Persona.PrimerApellido)
 0102            .ThenBy(rl => rl.Persona.PrimerNombre)
 0103            .ToListAsync();
 0104    }
 105
 106    public async Task<bool> ExisteByCedulaAsync(string cedula)
 107    {
 0108        return await _context.RelacionesLaborales
 0109            .Include(rl => rl.Persona)
 0110            .AnyAsync(rl => rl.Persona.Cedula == cedula);
 0111    }
 112
 113    public async Task<RelacionLaboral> CreateAsync(RelacionLaboral relacionLaboral)
 114    {
 0115        relacionLaboral.FechaActualizacion = DateTime.UtcNow;
 0116        relacionLaboral.Estado = "activo";
 117
 0118        _context.RelacionesLaborales.Add(relacionLaboral);
 0119        await _context.SaveChangesAsync();
 120
 0121        return await GetByIdAsync(relacionLaboral.Id) ?? relacionLaboral;
 0122    }
 123
 124    public async Task<RelacionLaboral> UpdateAsync(RelacionLaboral relacionLaboral)
 125    {
 0126        relacionLaboral.FechaActualizacion = DateTime.UtcNow;
 127
 0128        _context.RelacionesLaborales.Update(relacionLaboral);
 0129        await _context.SaveChangesAsync();
 130
 0131        return await GetByIdAsync(relacionLaboral.Id) ?? relacionLaboral;
 0132    }
 133
 134    public async Task<bool> DarBajaAsync(long id, DateTime fechaBaja)
 135    {
 0136        var relacionLaboral = await _context.RelacionesLaborales.FindAsync(id);
 0137        if (relacionLaboral == null)
 0138            return false;
 139
 140        // Baja lógica
 0141        relacionLaboral.Estado = "inactivo";
 0142        relacionLaboral.FechaFin = fechaBaja;
 0143        relacionLaboral.FechaActualizacion = DateTime.UtcNow;
 144
 0145        await _context.SaveChangesAsync();
 0146        return true;
 0147    }
 148
 149    public async Task<MovimientoLaboral> CrearMovimientoAsync(MovimientoLaboral movimiento)
 150    {
 0151        _context.MovimientosLaborales.Add(movimiento);
 0152        await _context.SaveChangesAsync();
 153
 0154        return await _context.MovimientosLaborales
 0155            .Include(ml => ml.TipoMovimiento)
 0156            .Include(ml => ml.RelacionLaboral)
 0157            .FirstOrDefaultAsync(ml => ml.Id == movimiento.Id) ?? movimiento;
 0158    }
 159}
 160