< Summary

Information
Class: FAU.DataAccess.Repositories.Form3100Repository
Assembly: FAU.DataAccess
File(s): /home/runner/work/Sistema.Liquidacion.BE/Sistema.Liquidacion.BE/FAU.DataAccess/Repositories/Form3100Repository.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 50
Coverable lines: 50
Total lines: 90
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%
GetByIdAsync()100%210%
GetVigenteParaPeriodoAsync()100%210%
GetHistorialAsync()0%2040%
ExisteVigenciaAsync()0%620%
CreateAsync()100%210%
AddPersonaACargoAsync()100%210%
GetPersonaACargoAsync()100%210%
DeletePersonaACargoAsync()0%620%
UpdateAsync()100%210%

File(s)

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

#LineLine coverage
 1using FAU.Entidades;
 2using Microsoft.EntityFrameworkCore;
 3
 4namespace FAU.DataAccess.Repositories;
 5
 6public class Form3100Repository : IForm3100Repository
 7{
 8    private readonly ApplicationDbContext _context;
 9
 010    public Form3100Repository(ApplicationDbContext context) => _context = context;
 11
 12    public async Task<Form3100?> GetByIdAsync(long id) =>
 013        await _context.Form3100
 014            .Include(f => f.PersonasACargo)
 015            .Include(f => f.Documento)
 016            .FirstOrDefaultAsync(f => f.Id == id);
 17
 18    public async Task<Form3100?> GetVigenteParaPeriodoAsync(long personaId, int anio, int mes)
 19    {
 020        return await _context.Form3100
 021            .Include(f => f.PersonasACargo)
 022            .Include(f => f.Documento)
 023            .Where(f => f.PersonaId == personaId &&
 024                        (f.VigenteDesde_Anio < anio ||
 025                         (f.VigenteDesde_Anio == anio && f.VigenteDesde_Mes <= mes)))
 026            .OrderByDescending(f => f.VigenteDesde_Anio)
 027            .ThenByDescending(f => f.VigenteDesde_Mes)
 028            .FirstOrDefaultAsync();
 029    }
 30
 31    public async Task<IEnumerable<Form3100>> GetHistorialAsync(long personaId, int? anio = null, int? mes = null)
 32    {
 033        var query = _context.Form3100
 034            .Include(f => f.PersonasACargo)
 035            .Where(f => f.PersonaId == personaId);
 36
 037        if (anio.HasValue) query = query.Where(f => f.VigenteDesde_Anio == anio.Value);
 038        if (mes.HasValue)  query = query.Where(f => f.VigenteDesde_Mes  == mes.Value);
 39
 040        return await query
 041            .OrderByDescending(f => f.VigenteDesde_Anio)
 042            .ThenByDescending(f => f.VigenteDesde_Mes)
 043            .ToListAsync();
 044    }
 45
 46    public async Task<bool> ExisteVigenciaAsync(long personaId, int anio, int mes, long? excludeId = null)
 47    {
 048        var query = _context.Form3100.Where(f =>
 049            f.PersonaId == personaId &&
 050            f.VigenteDesde_Anio == anio &&
 051            f.VigenteDesde_Mes  == mes);
 52
 053        if (excludeId.HasValue) query = query.Where(f => f.Id != excludeId.Value);
 054        return await query.AnyAsync();
 055    }
 56
 57    public async Task<Form3100> CreateAsync(Form3100 form)
 58    {
 059        _context.Form3100.Add(form);
 060        await _context.SaveChangesAsync();
 061        return form;
 062    }
 63
 64    public async Task<Form3100PersonaACargo> AddPersonaACargoAsync(Form3100PersonaACargo persona)
 65    {
 066        _context.Form3100PersonasACargo.Add(persona);
 067        await _context.SaveChangesAsync();
 068        return persona;
 069    }
 70
 71    public async Task<Form3100PersonaACargo?> GetPersonaACargoAsync(long id) =>
 072        await _context.Form3100PersonasACargo.FindAsync(id);
 73
 74    public async Task DeletePersonaACargoAsync(long id)
 75    {
 076        var p = await _context.Form3100PersonasACargo.FindAsync(id);
 077        if (p != null)
 78        {
 079            _context.Form3100PersonasACargo.Remove(p);
 080            await _context.SaveChangesAsync();
 81        }
 082    }
 83
 84    public async Task<Form3100> UpdateAsync(Form3100 form)
 85    {
 086        _context.Form3100.Update(form);
 087        await _context.SaveChangesAsync();
 088        return form;
 089    }
 90}