< Summary

Information
Class: LifeChart.Infrastructure.Repositories.MedicationRepository
Assembly: LifeChart.Infrastructure
File(s): /home/runner/work/lifechart/lifechart/src/LifeChart.Infrastructure/Repositories/MedicationRepository.cs
Tag: 113_29159449707
Line coverage
0%
Covered lines: 0
Uncovered lines: 17
Coverable lines: 17
Total lines: 40
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
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%
GetAllActiveAsync()100%210%
GetByIdAsync()100%210%
SaveAsync()0%620%
DeleteAsync()0%620%

File(s)

/home/runner/work/lifechart/lifechart/src/LifeChart.Infrastructure/Repositories/MedicationRepository.cs

#LineLine coverage
 1using LifeChart.Domain.Medications;
 2using LifeChart.Infrastructure.Persistence;
 3using Microsoft.EntityFrameworkCore;
 4
 5namespace LifeChart.Infrastructure.Repositories;
 6
 7public class MedicationRepository : IMedicationRepository
 8{
 9    private readonly LifeChartDbContext _context;
 10
 011    public MedicationRepository(LifeChartDbContext context)
 012        => _context = context;
 13
 14    public async Task<IEnumerable<Medication>> GetAllActiveAsync()
 015        => await _context.Medications
 016            .Where(m => m.Active)
 017            .OrderBy(m => m.Name)
 018            .ToListAsync();
 19
 20    public async Task<Medication?> GetByIdAsync(int id)
 021        => await _context.Medications.FirstOrDefaultAsync(m => m.Id == id);
 22
 23    public async Task SaveAsync(Medication medication)
 24    {
 025        if (medication.Id == 0)
 026            _context.Medications.Add(medication);
 27        else
 028            _context.Medications.Update(medication);
 29
 030        await _context.SaveChangesAsync();
 031    }
 32
 33    public async Task DeleteAsync(int id)
 34    {
 035        var medication = await GetByIdAsync(id);
 036        if (medication is null) return;
 037        medication.Deactivate();
 038        await _context.SaveChangesAsync();
 039    }
 40}