Files
Distribution_GL/Repositories/FiscalCalendarRepository.cs

41 lines
1.8 KiB
C#

using General_Ledger_Service.Infra;
using General_Ledger_Service.Interfaces.Repositories;
using General_Ledger_Service.Models;
using Microsoft.EntityFrameworkCore;
namespace General_Ledger_Service.Repositories
{
public class FiscalCalendarRepository(AppDBContext context) : IFiscalCalendarRepository
{
private readonly AppDBContext _context = context;
public Task<FiscalYear?> GetFiscalYearByIdAsync(int fiscalYearId) =>
RepositoryHelpers.GetByIdAsync(_context.FiscalYears, fiscalYearId);
public Task<bool> HasOverlappingFiscalYearRangeAsync(DateOnly startDate, DateOnly endDate) =>
RepositoryHelpers.ExistsAsync(_context.FiscalYears, fy => startDate <= fy.EndDate && endDate >= fy.StartDate);
public Task<FiscalYear> AddFiscalYearAsync(FiscalYear fiscalYear) =>
RepositoryHelpers.AddAsync(_context.FiscalYears, fiscalYear);
public Task<AccountingPeriod?> GetPeriodByIdAsync(int periodId) =>
RepositoryHelpers.GetByIdAsync(_context.AccountingPeriods, periodId);
public async Task<AccountingPeriod?> GetPeriodByDateAsync(DateOnly date) =>
await _context.AccountingPeriods
.FirstOrDefaultAsync(p => p.StartDate <= date && p.EndDate >= date);
public async Task<List<AccountingPeriod>> GetPeriodsByFiscalYearIdAsync(int fiscalYearId) =>
await _context.AccountingPeriods
.Where(p => p.FiscalYearId == fiscalYearId)
.OrderBy(p => p.PeriodNumber)
.ToListAsync();
public async Task AddPeriodRangeAsync(IEnumerable<AccountingPeriod> periods) =>
await _context.AccountingPeriods.AddRangeAsync(periods);
public Task<PeriodLockLog> AddPeriodLockLogAsync(PeriodLockLog log) =>
RepositoryHelpers.AddAsync(_context.PeriodLockLogs, log);
}
}