Files
2026-03-31 14:32:23 -05:00

105 lines
5.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using LCU.Library.Internal.ApiSecurity.Enums;
using LCU.Library.Internal.ApiSecurity.Models;
using LCU.Library.Internal.CoreApiWrapperLib.Configuration;
using LCU.Library.Internal.CoreApiWrapperLib.CoreDbUtilities;
using LCU.Library.Internal.CoreApiWrapperLib.Utilities;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.IndirectLoan;
using LCU.Library.Internal.LcuHttpClient.HttpRequest;
namespace LCU.Library.Internal.CoreApiWrapperLib.DataAccess
{
public class IndirectLoanDao : IIndirectLoanDao
{
private readonly ICoreDbExecution _coreDbExecution;
private readonly CoreSoapApiConfiguration _coreSoapApiConfiguration;
private readonly ApiSecurityConfiguration _apiSecurityConfiguration;
private readonly IPutRequest _putRequest;
private const string SoapClientKeyValue = "CoreSoapApiWrapper";
private const string indirectLoanByAcctNbrQuery = "IndirectLoan/IndirectLoan_ByAcctNbr_Query";
private const string indirectLoanByPostedDateQuery = "IndirectLoan/IndirectLoan_ByPostedDate_Query";
private const string closedIndirectLoanByPostedDateQuery = "IndirectLoan/ClosedIndirectLoan_ByPostedDate_Query";
private const string closedIndirectLoanWithDetailByPostedDateQuery = "IndirectLoan/ClosedIndirectLoanWithDetail_ByPostedDate_Query";
private const string DnaTimeFormat = "yyyy-MM-dd HH:mm:ss";
public IndirectLoanDao(ICoreDbExecution coreDbExecution,
CoreConfiguration coreConfiguration,
ApiSecurityConfiguration apiSecurityConfiguration,
IPutRequest putRequest)
{
_coreSoapApiConfiguration = coreConfiguration.CoreSoapApiConfiguration;
_coreDbExecution = coreDbExecution;
_apiSecurityConfiguration = apiSecurityConfiguration;
_putRequest = putRequest;
}
/// <summary>
/// Searches for indirect loans based on account number using SQL query.
/// Default Included: Graph
/// </summary>
/// <param name="accountNumber"></param>
/// <returns>IEnumerable<IndirectLoanDetail></returns>
public async Task<IEnumerable<IndirectLoanDetail>> FindByAccountNumber(long accountNumber)
{
var query = QueryUtilities.GetQuery(indirectLoanByAcctNbrQuery);
var accountNumberParam = new { AcctNbr = accountNumber };
var results = await _coreDbExecution.ExecuteQuery<IndirectLoanDetail, object>(query, accountNumberParam);
return results;
}
/// <summary>
/// Searches for indirect loans with posted date greater than the parameter using SQL query.
/// Default Included: Graph
/// </summary>
/// <param name="newerThanDateTime"></param>
/// <returns>IEnumerable<IndirectLoanDetail></returns>
public async Task<IEnumerable<IndirectLoanDetail>> FindByPostedDate(DateTime newerThanDateTime)
{
var query = QueryUtilities.GetQuery(indirectLoanByPostedDateQuery);
var newerThanDateTimeParam = new { newerThanDateTime = newerThanDateTime.ToString(DnaTimeFormat) };
var results = await _coreDbExecution.ExecuteQuery<IndirectLoanDetail, object>(query, newerThanDateTimeParam);
return results;
}
/// <summary>
/// Searches for closed indirect loans with closed date greater than the parameter using SQL query.
/// Default Included: Graph
/// </summary>
/// <param name="newerThanDateTime"></param>
/// <returns>IEnumerable<IndirectLoanDetail></returns>
public async Task<IEnumerable<ClosedIndirectLoan>> FindClosedByPostedDate(DateTime newerThanDateTime)
{
var query = QueryUtilities.GetQuery(closedIndirectLoanByPostedDateQuery);
var newerThanDateTimeParam = new { newerThanDateTime = newerThanDateTime.ToString(DnaTimeFormat) };
var results = await _coreDbExecution.ExecuteQuery<ClosedIndirectLoan, object>(query, newerThanDateTimeParam);
return results;
}
/// <summary>
/// Searches for closed indirect loans with detail with closed date greater than the parameter using SQL query.
/// Default Included: Graph
/// </summary>
/// <param name="newerThanDateTime"></param>
/// <returns>IEnumerable<IndirectLoanDetail></returns>
public async Task<IEnumerable<IndirectLoanDetail>> FindClosedWithDetailByPostedDate(DateTime newerThanDateTime)
{
var query = QueryUtilities.GetQuery(closedIndirectLoanWithDetailByPostedDateQuery);
var newerThanDateTimeParam = new { newerThanDateTime = newerThanDateTime.ToString(DnaTimeFormat) };
var results = await _coreDbExecution.ExecuteQuery<IndirectLoanDetail, object>(query, newerThanDateTimeParam);
return results;
}
public async Task<IEnumerable<UpdateDealerOriginalBalanceResponse>> UpdateDealerOriginalBalance(string accountNumber)
{
var endpoint = HttpUtilities.BuildHttpsUri(_coreSoapApiConfiguration.CoreSoapApiWrapperHost, _coreSoapApiConfiguration.CoreSoapEndpointConfiguration.PutDealerOriginalBalance + $"?accountNumber={accountNumber}");
var headers = LcuHttpClient.Utilities.HttpUtilities.GetApiKeyHeaders(SoapClientKeyValue, _apiSecurityConfiguration.ExtractApiKey(SoapClientKeyValue, ApiKeySetName.InternalKeySet));
return await _putRequest.Async<string, List<UpdateDealerOriginalBalanceResponse>>(endpoint, null, headers, 0);
}
}
}