Adding
This commit is contained in:
+7
@@ -0,0 +1,7 @@
|
||||
using LCU.Library.Internal.LcuCaching.Configurations;
|
||||
|
||||
namespace LCU.API.Internal.LoanRateLib.Configurations;
|
||||
|
||||
public class RateCacheConfiguration : CacheConfiguration
|
||||
{
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
using LCU.Library.Internal.LcuCaching.Configurations;
|
||||
|
||||
namespace LCU.API.Internal.LoanRateLib.Configurations;
|
||||
|
||||
public class RateSheetCacheConfiguration : CacheConfiguration
|
||||
{
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
namespace LCU.API.Internal.LoanRateLib.Configurations;
|
||||
|
||||
public class RateUploadInfoCacheConfiguration
|
||||
{
|
||||
public string CacheName { get; set; }
|
||||
public int ExpirationMinutes { get; set; }
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
namespace LCU.API.Internal.LoanRateLib.Extensions.Queryables;
|
||||
|
||||
public static class IncludeAllQueryable
|
||||
{
|
||||
public static IQueryable<Rate> IncludeAll(this IQueryable<Rate> queryable)
|
||||
{
|
||||
return queryable.Include(rate => rate.RateEvaluations);
|
||||
}
|
||||
|
||||
public static IQueryable<Rate> IncludeAllRatesEvaluations(this IQueryable<Rate> queryable)
|
||||
{
|
||||
return queryable.Include(rate => rate.RateEvaluations)
|
||||
.ThenInclude(rate => rate.EvaluationDetail);
|
||||
}
|
||||
|
||||
public static IQueryable<RateUploadInfo> IncludeAll(this IQueryable<RateUploadInfo> queryable)
|
||||
{
|
||||
return queryable.Include(rateUploadInfo => rateUploadInfo.Rates)
|
||||
.Include(rateUploadInfo => rateUploadInfo.ClosedRates)
|
||||
.ThenInclude(rate => rate.RateEvaluations);
|
||||
}
|
||||
|
||||
public static IQueryable<RateUploadInfo> IncludeAllButClosedRates(this IQueryable<RateUploadInfo> queryable)
|
||||
{
|
||||
return queryable.Include(rateUploadInfo => rateUploadInfo.Rates)
|
||||
.ThenInclude(rate => rate.RateEvaluations);
|
||||
}
|
||||
|
||||
public static IQueryable<RateSheet> IncludeAll(this IQueryable<RateSheet> queryable)
|
||||
{
|
||||
return queryable.Include(rateSheet => rateSheet.RateSheetCells)
|
||||
.Include(rateSheet => rateSheet.Rates)
|
||||
.ThenInclude(rate => rate.RateEvaluations);
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
namespace LCU.API.Internal.LoanRateLib.Extensions.Queryables;
|
||||
public static class IncludeFiltersQueryable
|
||||
{
|
||||
public static IQueryable<RateUploadInfo> IncludeFilters(this IQueryable<RateUploadInfo> queryable, RateUploadInfoFilter rateUploadInfoFilter)
|
||||
=> queryable.FilterByEffectiveDate(rateUploadInfoFilter)
|
||||
.FilterByVersion(rateUploadInfoFilter)
|
||||
.FilterByCreatedBy(rateUploadInfoFilter);
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
namespace LCU.API.Internal.LoanRateLib.Extensions.Queryables;
|
||||
public static class RateUploadInfoCreatedByQueryable
|
||||
{
|
||||
public static IQueryable<RateUploadInfo> FilterByCreatedBy(this IQueryable<RateUploadInfo> queryable, RateUploadInfoFilter rateUploadInfoFilter)
|
||||
{
|
||||
if (rateUploadInfoFilter.CreatedBy == null)
|
||||
{
|
||||
return queryable;
|
||||
}
|
||||
|
||||
return queryable.Where(rateUploadInfo => rateUploadInfo.CreatedBy.ToUpper().Contains(rateUploadInfoFilter.CreatedBy.ToUpper()));
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
namespace LCU.API.Internal.LoanRateLib.Extensions.Queryables;
|
||||
public static class RateUploadInfoEffectiveDateQueryable
|
||||
{
|
||||
public static IQueryable<RateUploadInfo> FilterByEffectiveDate(this IQueryable<RateUploadInfo> queryable, RateUploadInfoFilter rateUploadInfoFilter)
|
||||
{
|
||||
if (rateUploadInfoFilter.EffectiveDate == null)
|
||||
{
|
||||
return queryable;
|
||||
}
|
||||
|
||||
return queryable.Where(rateUploadInfo => rateUploadInfo.EffectiveDate.Date == ((DateTime)rateUploadInfoFilter.EffectiveDate).Date);
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
namespace LCU.API.Internal.LoanRateLib.Extensions.Queryables;
|
||||
public static class RateUploadInfoVersionQueryable
|
||||
{
|
||||
public static IQueryable<RateUploadInfo> FilterByVersion(this IQueryable<RateUploadInfo> queryable, RateUploadInfoFilter rateUploadInfoFilter)
|
||||
{
|
||||
if (rateUploadInfoFilter.Version == null)
|
||||
{
|
||||
return queryable;
|
||||
}
|
||||
|
||||
return queryable.Where(rateUploadInfo => rateUploadInfo.Version == (int)rateUploadInfoFilter.Version);
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
using System.Linq.Dynamic.Core;
|
||||
using System.Text;
|
||||
|
||||
namespace LCU.API.Internal.LoanRateLib.Extensions.Queryables;
|
||||
public static class SortableFieldsQueryable
|
||||
{
|
||||
public static IQueryable<RateUploadInfo> OrderBySortableFields(this IQueryable<RateUploadInfo> queryable, RateUploadInfoFilter rateUploadInfoFilter)
|
||||
{
|
||||
var sortableFields = rateUploadInfoFilter.SortableFields
|
||||
.Where(sortableField => sortableField.Active && sortableField.Position >= 0)
|
||||
.OrderBy(sortableField => sortableField.Position).ToList();
|
||||
|
||||
if (sortableFields == null || !sortableFields.Any())
|
||||
{
|
||||
return queryable;
|
||||
}
|
||||
|
||||
var orderBy = new StringBuilder();
|
||||
foreach (var field in sortableFields)
|
||||
{
|
||||
var addedComma = orderBy.ToString() == "" ? "" : " ,";
|
||||
var desc = field.IsDescending ? " desc" : "";
|
||||
orderBy.Append($"{addedComma}{field.Field}{desc}");
|
||||
}
|
||||
|
||||
return queryable.OrderBy(orderBy.ToString());
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LCU.Library.Internal.LcuCaching" Version="1.0.0" />
|
||||
<PackageReference Include="LCU.Library.Internal.LcuClassPatterns.Crud" Version="1.0.2" />
|
||||
<PackageReference Include="LCU.Library.Internal.TypeExtensions" Version="1.2.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.8" />
|
||||
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\LCU.Library.Internal.LoanRateModels\LCU.Library.Internal.LoanRateModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,45 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
namespace LCU.API.Internal.LoanRateLib.Persistence;
|
||||
|
||||
public class AppDbContext : DbContext
|
||||
{
|
||||
public DbSet<Rate> Rates { get; set; }
|
||||
public DbSet<RateEvaluation> RateEvaluations { get; set; }
|
||||
public DbSet<RateUploadInfo> RateUploadInfos { get; set; }
|
||||
public DbSet<RateSheet> RateSheets { get; set; }
|
||||
public DbSet<RateSheetCell> RateSheetCells { get; set; }
|
||||
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
base.OnModelCreating(builder);
|
||||
|
||||
builder.Entity<Rate>().ToTable("Rate");
|
||||
builder.Entity<RateEvaluation>().ToTable("RateEvaluation");
|
||||
builder.Entity<RateUploadInfo>().ToTable("RateUploadInfo")
|
||||
.HasMany(rateUploadInfo => rateUploadInfo.Rates)
|
||||
.WithOne()
|
||||
.HasForeignKey(rate => rate.RateUploadInfoId)
|
||||
.IsRequired(false)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
builder.Entity<RateUploadInfo>().ToTable("RateUploadInfo")
|
||||
.HasMany(rateUploadInfo => rateUploadInfo.ClosedRates)
|
||||
.WithOne()
|
||||
.HasForeignKey(rate => rate.ClosingRateUploadInfoId)
|
||||
.IsRequired(false)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
builder.Entity<RateSheet>().ToTable("RateSheet")
|
||||
.HasMany(rateSheet => rateSheet.Rates)
|
||||
.WithOne()
|
||||
.HasForeignKey(rate => rate.RateSheetId)
|
||||
.IsRequired(false)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
builder.Entity<RateSheet>().ToTable("RateSheet")
|
||||
.HasMany(rateSheet => rateSheet.RateSheetCells)
|
||||
.WithOne()
|
||||
.HasForeignKey(rateSheetCell => rateSheetCell.RateSheetId)
|
||||
.IsRequired(false)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
builder.Entity<RateSheetCell>().ToTable("RateSheetCell");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using LCU.API.Internal.LoanRateLib.Persistence;
|
||||
namespace LCU.API.Internal.LoanRateLib.Repositories;
|
||||
|
||||
public abstract class BaseRepository
|
||||
{
|
||||
protected readonly AppDbContext _context;
|
||||
|
||||
public BaseRepository(AppDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
using LCU.Library.Internal.LoanRateModels.Enums;
|
||||
|
||||
namespace LCU.API.Internal.LoanRateLib.Repositories;
|
||||
|
||||
public interface IRateEvaluationRepository
|
||||
{
|
||||
Task<IEnumerable<RateEvaluation>?> FindAsync();
|
||||
Task<RateEvaluation?> FindByIdAsync(int id);
|
||||
Task<IEnumerable<RateEvaluation>?> FindRangeByIdAsync(List<int> ids);
|
||||
Task<IEnumerable<RateEvaluation>?> FindRangeByEvaluationDetailIdAsync(int evaluationDetailId);
|
||||
Task<IEnumerable<RateEvaluation>?> FindByRateSheetIdsAsync(List<int> rateSheetIds);
|
||||
Task<RateEvaluation?> AddAsync(RateEvaluation rateEvaluation);
|
||||
Task AddRangeAsync(IEnumerable<RateEvaluation> rateEvaluations);
|
||||
void UpdateRange(IEnumerable<RateEvaluation> rateEvaluations);
|
||||
void Remove(RateEvaluation rateEvaluation);
|
||||
void RemoveRange(IEnumerable<RateEvaluation> rateEvaluations);
|
||||
Task<int> CountByEvaluationDetailIdAsync(int evaluationDetailId);
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
using LCU.Library.Internal.LcuEvaluationModels.Enums;
|
||||
|
||||
namespace LCU.API.Internal.LoanRateLib.Repositories;
|
||||
public interface IRateRepository
|
||||
{
|
||||
Task<IEnumerable<Rate>?> FindAsync();
|
||||
Task<IEnumerable<Rate>?> FindWithRateEvaluationsAsync();
|
||||
Task<Rate?> FindByIdAsync(int id);
|
||||
Task<IEnumerable<Rate>?> FindByClosingRateUploadInfoIdAsync(int id);
|
||||
Task<IEnumerable<Rate>?> FindByDateAsync(DateTime date);
|
||||
Task<IEnumerable<Rate>?> FindRateHistoryAsync(Rate rate);
|
||||
Task<IEnumerable<Rate>?> FindRangeByIdAsync(List<int> ids);
|
||||
Task<IEnumerable<Rate>?> FindByDateEvaluationIdsAndEvaluationTypeAsync(DateTime date,
|
||||
List<int> evaluationIds,
|
||||
EvaluationTypes evaluationType);
|
||||
Task<Rate?> AddAsync(Rate rate);
|
||||
Task AddRangeAsync(IEnumerable<Rate> rates);
|
||||
void UpdateRange(IEnumerable<Rate> rates);
|
||||
void Remove(Rate rate);
|
||||
void RemoveRange(IEnumerable<Rate> rates);
|
||||
Task<IEnumerable<Rate>> FindCacheAsync();
|
||||
void ClearCache();
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
using LCU.Library.Internal.LcuClassPatterns.Crud.Repositories;
|
||||
|
||||
namespace LCU.API.Internal.LoanRateLib.Repositories;
|
||||
public interface IRateSheetCellRepository : ICrudRepository<RateSheetCell>
|
||||
{
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
using LCU.Library.Internal.LcuClassPatterns.Crud.Repositories;
|
||||
using LCU.Library.Internal.LoanRateModels.Enums;
|
||||
|
||||
namespace LCU.API.Internal.LoanRateLib.Repositories;
|
||||
public interface IRateSheetRepository : ICrudRepository<RateSheet>
|
||||
{
|
||||
Task<IEnumerable<RateSheet>> FindIncludeAllAsync();
|
||||
Task<IEnumerable<RateSheet>> FindIncludeRateSheetCellsAsync();
|
||||
Task<IEnumerable<Rate>?> FindRatesByDateAndRateType(DateTime date, RateTypes rateType);
|
||||
Task<RateSheet?> FindByDateAndRateType(DateTime date, RateTypes rateType);
|
||||
Task<IEnumerable<Rate>?> FindRatesByRateType(RateTypes rateType);
|
||||
Task<IEnumerable<int>?> FindRateSheetIdsByRateType(RateTypes rateType);
|
||||
Task<IEnumerable<RateSheet>> FindCacheAsync();
|
||||
void ClearCache();
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
using LCU.Library.Internal.LcuClassPatterns.Crud.Repositories;
|
||||
using LCU.Library.Internal.LoanRateModels.Responses;
|
||||
|
||||
namespace LCU.API.Internal.LoanRateLib.Repositories;
|
||||
public interface IRateUploadInfoRepository : ICrudRepository<RateUploadInfo>
|
||||
{
|
||||
Task<RateUploadInfo?> FindLatestAsync();
|
||||
Task<RateUploadInfo?> FindByVersionAsync(int version, DateTime effectiveDate);
|
||||
Task<RateUploadInfo?> FindPreviousVersion(RateUploadInfo rateUploadInfo);
|
||||
Task<RateUploadInfo?> FindLatestVersionOnDate(DateTime effectiveDate);
|
||||
Task<RateUploadInfoFilterResult> FindFilteredRateUploadInfosAsync(RateUploadInfoFilter rateUploadInfoFilter);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace LCU.API.Internal.LoanRateLib.Repositories;
|
||||
|
||||
public interface IUnitOfWork
|
||||
{
|
||||
Task CompleteAsync();
|
||||
void Complete();
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using LCU.API.Internal.LoanRateLib.Persistence;
|
||||
using LCU.Library.Internal.LoanRateModels.Enums;
|
||||
|
||||
namespace LCU.API.Internal.LoanRateLib.Repositories;
|
||||
|
||||
public class RateEvaluationRepository : BaseRepository, IRateEvaluationRepository
|
||||
{
|
||||
public IRateRepository _rateRepository;
|
||||
|
||||
public RateEvaluationRepository(AppDbContext context,
|
||||
IRateRepository rateRepository) : base(context)
|
||||
{
|
||||
_rateRepository = rateRepository;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<RateEvaluation>?> FindAsync()
|
||||
{
|
||||
return await _context.RateEvaluations.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<RateEvaluation?> FindByIdAsync(int id)
|
||||
{
|
||||
return await _context.RateEvaluations.FirstOrDefaultAsync(rateEvaluation => rateEvaluation.RateEvaluationId == id);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<RateEvaluation>?> FindRangeByIdAsync(List<int> ids)
|
||||
{
|
||||
return await _context.RateEvaluations
|
||||
.Where(rateEvaluation => ids.Contains(rateEvaluation.RateEvaluationId))
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<RateEvaluation>?> FindRangeByEvaluationDetailIdAsync(int evaluationDetailId)
|
||||
{
|
||||
return await _context.RateEvaluations
|
||||
.Where(rateEvaluation => rateEvaluation.EvaluationDetailId == evaluationDetailId)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<RateEvaluation>?> FindByRateSheetIdsAsync(List<int> rateSheetIds)
|
||||
{
|
||||
return (await _rateRepository.FindCacheAsync())
|
||||
.Where(rate => rateSheetIds.Contains(rate.RateSheetId))
|
||||
.SelectMany(rate => rate.RateEvaluations);
|
||||
}
|
||||
|
||||
public async Task<RateEvaluation?> AddAsync(RateEvaluation rateEvaluation)
|
||||
{
|
||||
return (await _context.RateEvaluations.AddAsync(rateEvaluation)).Entity;
|
||||
}
|
||||
|
||||
public async Task AddRangeAsync(IEnumerable<RateEvaluation> rateEvaluations)
|
||||
{
|
||||
await _context.RateEvaluations.AddRangeAsync(rateEvaluations);
|
||||
}
|
||||
|
||||
public void UpdateRange(IEnumerable<RateEvaluation> rateEvaluations)
|
||||
{
|
||||
_context.RateEvaluations.UpdateRange(rateEvaluations);
|
||||
}
|
||||
|
||||
public void Remove(RateEvaluation rateEvaluation)
|
||||
{
|
||||
_context.RateEvaluations.Remove(rateEvaluation);
|
||||
}
|
||||
|
||||
public void RemoveRange(IEnumerable<RateEvaluation> rateEvaluations)
|
||||
{
|
||||
_context.RateEvaluations.RemoveRange(rateEvaluations);
|
||||
}
|
||||
|
||||
public async Task<int> CountByEvaluationDetailIdAsync(int evaluationDetailId)
|
||||
{
|
||||
return await _context.RateEvaluations
|
||||
.Where(rateEvaluation => rateEvaluation.EvaluationDetailId == evaluationDetailId)
|
||||
.Select(rateEvaluation => rateEvaluation.RateId)
|
||||
.Distinct()
|
||||
.CountAsync();
|
||||
}
|
||||
}
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using LCU.API.Internal.LoanRateLib.Configurations;
|
||||
using LCU.API.Internal.LoanRateLib.Extensions.Queryables;
|
||||
using LCU.API.Internal.LoanRateLib.Persistence;
|
||||
using LCU.Library.Internal.LcuCaching.Services;
|
||||
using LCU.Library.Internal.LcuEvaluationModels.Enums;
|
||||
|
||||
namespace LCU.API.Internal.LoanRateLib.Repositories;
|
||||
|
||||
public class RateRepository : BaseRepository, IRateRepository
|
||||
{
|
||||
private readonly RateCacheConfiguration _rateCacheConfiguration;
|
||||
private readonly ICacheService _cacheService;
|
||||
|
||||
public RateRepository(AppDbContext context,
|
||||
RateCacheConfiguration rateCacheConfiguration,
|
||||
ICacheService cacheService) : base(context)
|
||||
{
|
||||
_rateCacheConfiguration = rateCacheConfiguration;
|
||||
_cacheService = cacheService;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Rate>?> FindAsync()
|
||||
{
|
||||
return await _context.Rates.IncludeAll().ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Rate>?> FindWithRateEvaluationsAsync()
|
||||
{
|
||||
return await _context.Rates.IncludeAllRatesEvaluations().ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<Rate?> FindByIdAsync(int id)
|
||||
{
|
||||
return await _context.Rates.IncludeAll().FirstOrDefaultAsync(rate => rate.RateId == id);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Rate>?> FindByClosingRateUploadInfoIdAsync(int id)
|
||||
{
|
||||
return await _context.Rates.Where(rate => rate.ClosingRateUploadInfoId == id)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Rate>?> FindByDateAsync(DateTime date)
|
||||
{
|
||||
return await _context.Rates.Where(rate => date >= rate.RateStartDate &&
|
||||
(rate.RateEndDate == null || date < rate.RateEndDate))
|
||||
.IncludeAll()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Rate>?> FindRateHistoryAsync(Rate rate)
|
||||
{
|
||||
return await _context.Rates.Where(x => x.Row == rate.Row
|
||||
&& x.Column == rate.Column
|
||||
&& x.RateSheetId == rate.RateSheetId)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Rate>?> FindRangeByIdAsync(List<int> ids)
|
||||
{
|
||||
return await _context.Rates
|
||||
.Where(rate => ids.Contains(rate.RateId))
|
||||
.IncludeAll()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Will get Rates that:
|
||||
/// - Are between the RateStartDate-RateEndDate(if not null).
|
||||
/// - Match the evaluation type
|
||||
/// - Match All the EvaluationIds
|
||||
/// - Contains ALL the evaluationids and the count of RateEvaluation.EvaluationDetailIds match the count of evaluationIds
|
||||
/// </summary>
|
||||
/// <param name="date"></param>
|
||||
/// <param name="evaluationIds"></param>
|
||||
/// <param name="evaluationType"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<Rate>?> FindByDateEvaluationIdsAndEvaluationTypeAsync(DateTime date,
|
||||
List<int> evaluationIds,
|
||||
EvaluationTypes evaluationType)
|
||||
{
|
||||
return await _context.Rates
|
||||
.Where(
|
||||
rate => date >= rate.RateStartDate &&
|
||||
(!rate.RateEndDate.HasValue || date < rate.RateEndDate) &&
|
||||
(rate.RateEvaluations.Any() &&
|
||||
rate.RateEvaluations
|
||||
.Where(rateEvaluation =>
|
||||
(date >= rateEvaluation.EvaluationDetail.StartDate &&
|
||||
(!rateEvaluation.EvaluationDetail.EndDate.HasValue || date < rateEvaluation.EvaluationDetail.EndDate)) &&
|
||||
rateEvaluation.EvaluationDetail.EvaluationType == evaluationType &&
|
||||
rateEvaluation.EvaluationDetail.Active == true)
|
||||
.All(rateEvaluation => evaluationIds.Contains(rateEvaluation.EvaluationDetailId)) &&
|
||||
rate.RateEvaluations
|
||||
.Where(rateEvaluation =>
|
||||
(date >= rateEvaluation.EvaluationDetail.StartDate &&
|
||||
(!rateEvaluation.EvaluationDetail.EndDate.HasValue || date < rateEvaluation.EvaluationDetail.EndDate)) &&
|
||||
rateEvaluation.EvaluationDetail.EvaluationType == evaluationType &&
|
||||
rateEvaluation.EvaluationDetail.Active == true &&
|
||||
evaluationIds.Contains(rateEvaluation.EvaluationDetailId))
|
||||
.Select(rateEvaluation => rateEvaluation.EvaluationDetailId).Count() == evaluationIds.Count))
|
||||
.IncludeAllRatesEvaluations()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<Rate?> AddAsync(Rate rate)
|
||||
{
|
||||
return (await _context.Rates.AddAsync(rate)).Entity;
|
||||
}
|
||||
|
||||
public async Task AddRangeAsync(IEnumerable<Rate> rates)
|
||||
{
|
||||
await _context.Rates.AddRangeAsync(rates);
|
||||
}
|
||||
|
||||
public void UpdateRange(IEnumerable<Rate> rates)
|
||||
{
|
||||
_context.Rates.UpdateRange(rates);
|
||||
}
|
||||
|
||||
public void Remove(Rate rate)
|
||||
{
|
||||
_context.Rates.Remove(rate);
|
||||
}
|
||||
|
||||
public void RemoveRange(IEnumerable<Rate> rates)
|
||||
{
|
||||
_context.Rates.RemoveRange(rates);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Rate>> FindCacheAsync()
|
||||
=> await _cacheService.FindCacheAsync(FindAsync,
|
||||
_rateCacheConfiguration.CacheName,
|
||||
_rateCacheConfiguration.ExpirationMinutes);
|
||||
|
||||
public void ClearCache()
|
||||
=> _cacheService.ClearCache(_rateCacheConfiguration.CacheName);
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
using LCU.API.Internal.LoanRateLib.Persistence;
|
||||
using LCU.Library.Internal.LcuClassPatterns.Crud.Repositories;
|
||||
|
||||
namespace LCU.API.Internal.LoanRateLib.Repositories;
|
||||
public class RateSheetCellRepository : CrudRepository<RateSheetCell>, IRateSheetCellRepository
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public RateSheetCellRepository(AppDbContext context) : base(context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
using LCU.API.Internal.LoanRateLib.Configurations;
|
||||
using LCU.API.Internal.LoanRateLib.Extensions.Queryables;
|
||||
using LCU.API.Internal.LoanRateLib.Persistence;
|
||||
using LCU.Library.Internal.LcuCaching.Services;
|
||||
using LCU.Library.Internal.LcuClassPatterns.Crud.Repositories;
|
||||
using LCU.Library.Internal.LoanRateModels.Enums;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LCU.API.Internal.LoanRateLib.Repositories;
|
||||
public class RateSheetRepository : CrudRepository<RateSheet>, IRateSheetRepository
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
private readonly RateSheetCacheConfiguration _rateSheetCacheConfiguration;
|
||||
private readonly ICacheService _cacheService;
|
||||
|
||||
public RateSheetRepository(AppDbContext context,
|
||||
RateSheetCacheConfiguration rateSheetCacheConfiguration,
|
||||
ICacheService cacheService) : base(context)
|
||||
{
|
||||
_context = context;
|
||||
_rateSheetCacheConfiguration = rateSheetCacheConfiguration;
|
||||
_cacheService = cacheService;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<RateSheet>> FindIncludeAllAsync()
|
||||
{
|
||||
return await _context.RateSheets.IncludeAll().ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<RateSheet>> FindIncludeRateSheetCellsAsync()
|
||||
{
|
||||
return await _context.RateSheets.Include(rateSheet => rateSheet.RateSheetCells).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Rate>?> FindRatesByDateAndRateType(DateTime date, RateTypes rateType)
|
||||
{
|
||||
return (await FindCacheAsync()).FirstOrDefault(rateSheet => rateSheet.RateType == rateType)?
|
||||
.Rates.Where(rate =>
|
||||
date >= rate.RateStartDate
|
||||
&& (rate.RateEndDate == null || date < rate.RateEndDate));
|
||||
}
|
||||
|
||||
public async Task<RateSheet?> FindByDateAndRateType(DateTime date, RateTypes rateType)
|
||||
{
|
||||
return await _context.RateSheets.Include(rateSheet => rateSheet.Rates)
|
||||
.Include(rateSheet => rateSheet.RateSheetCells)
|
||||
.Where(rateSheet => rateSheet.RateType == rateType)
|
||||
.Select(rateSheet =>
|
||||
new RateSheet
|
||||
{
|
||||
RateSheetId = rateSheet.RateSheetId,
|
||||
RateType = rateSheet.RateType,
|
||||
RateSheetCells = rateSheet.RateSheetCells,
|
||||
Rates = _context.Rates.Where(rate => rate.RateSheetId == rateSheet.RateSheetId
|
||||
&& date >= rate.RateStartDate
|
||||
&& (rate.RateEndDate == null || date < rate.RateEndDate)).ToList(),
|
||||
CreatedBy = rateSheet.CreatedBy,
|
||||
TimeCreated = rateSheet.TimeCreated
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Rate>?> FindRatesByRateType(RateTypes rateType)
|
||||
{
|
||||
return (await FindCacheAsync()).FirstOrDefault(rateSheet => rateSheet.RateType == rateType)?.Rates;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<int>?> FindRateSheetIdsByRateType(RateTypes rateType)
|
||||
{
|
||||
return await _context.RateSheets.Where(rateSheet => rateSheet.RateType == rateType)
|
||||
.Select(rateSheet => rateSheet.RateSheetId)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<RateSheet>> FindCacheAsync()
|
||||
{
|
||||
return await _cacheService.FindCacheAsync(FindIncludeAllAsync,
|
||||
_rateSheetCacheConfiguration.CacheName,
|
||||
_rateSheetCacheConfiguration.ExpirationMinutes);
|
||||
}
|
||||
|
||||
public void ClearCache() => _cacheService.ClearCache(_rateSheetCacheConfiguration.CacheName);
|
||||
}
|
||||
+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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using LCU.API.Internal.LoanRateLib.Persistence;
|
||||
namespace LCU.API.Internal.LoanRateLib.Repositories;
|
||||
|
||||
public class UnitOfWork : IUnitOfWork
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UnitOfWork(AppDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task CompleteAsync()
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public void Complete()
|
||||
{
|
||||
_context.SaveChanges();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
global using LCU.Library.Internal.LoanRateModels.Entities;
|
||||
Reference in New Issue
Block a user