114 lines
3.6 KiB
C#
114 lines
3.6 KiB
C#
using LCU.API.Internal.LoanRateLib.Repositories;
|
|
using LCU.Library.Internal.LcuClassPatterns.Crud.Services;
|
|
using LCU.Library.Internal.LoanRateModels.Enums;
|
|
|
|
namespace LCU.API.Internal.LoanRate.Services;
|
|
|
|
public class RateSheetService : CrudService<RateSheet>, IRateSheetService
|
|
{
|
|
private readonly IRateSheetRepository _rateSheetRepository;
|
|
|
|
public RateSheetService(IRateSheetRepository rateSheetRepository) : base(rateSheetRepository)
|
|
{
|
|
_rateSheetRepository = rateSheetRepository;
|
|
}
|
|
|
|
public async Task<IEnumerable<RateSheet>?> GetIncludeAllAsync()
|
|
{
|
|
try
|
|
{
|
|
return await _rateSheetRepository.FindIncludeAllAsync() ?? new List<RateSheet>();
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
var message = "Failure during GetIncludeAllAsync.";
|
|
Log.Error(exception, message);
|
|
throw new ServiceException(message);
|
|
}
|
|
}
|
|
|
|
public async Task<IEnumerable<RateSheet>?> GetIncludeRateSheetCellsAsync()
|
|
{
|
|
try
|
|
{
|
|
return await _rateSheetRepository.FindIncludeRateSheetCellsAsync() ?? new List<RateSheet>();
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
var message = "Failure during GetIncludeRateSheetCellsAsync.";
|
|
Log.Error(exception, message);
|
|
throw new ServiceException(message);
|
|
}
|
|
}
|
|
|
|
public async Task<IEnumerable<Rate>?> GetRatesByRateTypeAsync(RateTypes rateType)
|
|
{
|
|
try
|
|
{
|
|
return await _rateSheetRepository.FindRatesByRateType(rateType) ?? new List<Rate>();
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
var message = $"Failure retrieving Rates with RateType: {rateType}.";
|
|
Log.Error(exception, message);
|
|
throw new ServiceException(message);
|
|
}
|
|
}
|
|
|
|
public async Task<IEnumerable<int>?> GetRateSheetIdsByRateTypeAsync(RateTypes rateType)
|
|
{
|
|
try
|
|
{
|
|
return await _rateSheetRepository.FindRateSheetIdsByRateType(rateType) ?? new List<int>();
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
var message = $"Failure retrieving RateSheetIds with RateType: {rateType}.";
|
|
Log.Error(exception, message);
|
|
throw new ServiceException(message);
|
|
}
|
|
}
|
|
|
|
public async Task<IEnumerable<Rate>?> GetRatesByDateAndRateTypeAsync(DateTime date, RateTypes rateType)
|
|
{
|
|
try
|
|
{
|
|
return await _rateSheetRepository.FindRatesByDateAndRateType(date, rateType) ?? new List<Rate>();
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
var message = $"Failure retrieving Rates with RateType ({rateType}) and Date: {date::MM-dd-yyyy HH:mm:ss}.";
|
|
Log.Error(exception, message);
|
|
throw new ServiceException(message);
|
|
}
|
|
}
|
|
|
|
public async Task<RateSheet?> GetByDateAndRateTypeAsync(DateTime date, RateTypes rateType)
|
|
{
|
|
try
|
|
{
|
|
return await _rateSheetRepository.FindByDateAndRateType(date, rateType);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
var message = $"Failure retrieving RateSheet with RateType ({rateType}) and Date: {date::MM-dd-yyyy HH:mm:ss}.";
|
|
Log.Error(exception, message);
|
|
throw new ServiceException(message);
|
|
}
|
|
}
|
|
|
|
public void ClearCache()
|
|
{
|
|
try
|
|
{
|
|
_rateSheetRepository.ClearCache();
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
var message = "Failure to clear cache for RateSheets";
|
|
|
|
Log.Error(exception, message);
|
|
throw new ServiceException(message);
|
|
}
|
|
}
|
|
} |