Adding
This commit is contained in:
+91
@@ -0,0 +1,91 @@
|
||||
using LCU.API.Internal.LoanRateLib.Extensions.Queryables;
|
||||
using LCU.API.Internal.LoanRateLib.Persistence;
|
||||
using LCU.Library.Internal.LcuClassPatterns.Crud.Repositories;
|
||||
using LCU.Library.Internal.LoanRateModels.Responses;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LCU.API.Internal.LoanRateLib.Repositories;
|
||||
public class RateUploadInfoRepository : CrudRepository<RateUploadInfo>, IRateUploadInfoRepository
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public RateUploadInfoRepository(AppDbContext context) : base(context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<RateUploadInfo?> FindLatestAsync()
|
||||
{
|
||||
return await _context.RateUploadInfos.OrderByDescending(r => r.EffectiveDate)
|
||||
.ThenByDescending(r => r.Version)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<RateUploadInfo?> FindByVersionAsync(int version, DateTime effectiveDate)
|
||||
{
|
||||
return await _context.RateUploadInfos.Where(rateUploadInfo => rateUploadInfo.EffectiveDate.Date == effectiveDate.Date
|
||||
&& rateUploadInfo.Version == version)
|
||||
.IncludeAllButClosedRates()
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<RateUploadInfo?> FindPreviousVersion(RateUploadInfo rateUploadInfo)
|
||||
{
|
||||
return await _context.RateUploadInfos.Where(r => r.EffectiveDate.Date <= rateUploadInfo.EffectiveDate.Date
|
||||
&& (r.EffectiveDate.Date != rateUploadInfo.EffectiveDate.Date || r.Version < rateUploadInfo.Version )
|
||||
&& r.RateUploadInfoId != rateUploadInfo.RateUploadInfoId)
|
||||
.OrderByDescending(r => r.EffectiveDate)
|
||||
.ThenByDescending(r => r.Version)
|
||||
.IncludeAllButClosedRates()
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<RateUploadInfo?> FindLatestVersionOnDate(DateTime effectiveDate)
|
||||
{
|
||||
return await _context.RateUploadInfos.Where(r => r.EffectiveDate.Date == effectiveDate.Date)
|
||||
.OrderByDescending(r => r.Version)
|
||||
.IncludeAllButClosedRates()
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public override async Task<IEnumerable<RateUploadInfo>> FindAsync()
|
||||
{
|
||||
return await _context.RateUploadInfos.IncludeAllButClosedRates().ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<RateUploadInfoFilterResult> FindFilteredRateUploadInfosAsync(RateUploadInfoFilter rateUploadInfoFilter)
|
||||
{
|
||||
var results = new RateUploadInfoFilterResult();
|
||||
var skip = (rateUploadInfoFilter.Page - 1) * rateUploadInfoFilter.Limit;
|
||||
|
||||
results.Total = await _context.RateUploadInfos
|
||||
.IncludeFilters(rateUploadInfoFilter)
|
||||
.CountAsync();
|
||||
|
||||
results.Items = await _context.RateUploadInfos
|
||||
.IncludeFilters(rateUploadInfoFilter)
|
||||
.OrderBySortableFields(rateUploadInfoFilter)
|
||||
.Skip(skip)
|
||||
.Take(rateUploadInfoFilter.Limit)
|
||||
.ToArrayAsync();
|
||||
|
||||
results.TotalCount = await _context.RateUploadInfos.CountAsync();
|
||||
results.LatestRateUploadInfo = await FindLatestAsync();
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public override async Task<RateUploadInfo> FindByIdAsync(int id)
|
||||
{
|
||||
return await _context.RateUploadInfos.Where(rateUploadInfo => rateUploadInfo.RateUploadInfoId == id)
|
||||
.IncludeAllButClosedRates()
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public override async Task<IEnumerable<RateUploadInfo>> FindRangeByIdAsync(List<int> ids)
|
||||
{
|
||||
return await _context.RateUploadInfos.Where(rateUploadInfo => ids.Contains(rateUploadInfo.RateUploadInfoId))
|
||||
.IncludeAllButClosedRates()
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user