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; } /// /// Searches for indirect loans based on account number using SQL query. /// Default Included: Graph /// /// /// IEnumerable public async Task> FindByAccountNumber(long accountNumber) { var query = QueryUtilities.GetQuery(indirectLoanByAcctNbrQuery); var accountNumberParam = new { AcctNbr = accountNumber }; var results = await _coreDbExecution.ExecuteQuery(query, accountNumberParam); return results; } /// /// Searches for indirect loans with posted date greater than the parameter using SQL query. /// Default Included: Graph /// /// /// IEnumerable public async Task> FindByPostedDate(DateTime newerThanDateTime) { var query = QueryUtilities.GetQuery(indirectLoanByPostedDateQuery); var newerThanDateTimeParam = new { newerThanDateTime = newerThanDateTime.ToString(DnaTimeFormat) }; var results = await _coreDbExecution.ExecuteQuery(query, newerThanDateTimeParam); return results; } /// /// Searches for closed indirect loans with closed date greater than the parameter using SQL query. /// Default Included: Graph /// /// /// IEnumerable public async Task> FindClosedByPostedDate(DateTime newerThanDateTime) { var query = QueryUtilities.GetQuery(closedIndirectLoanByPostedDateQuery); var newerThanDateTimeParam = new { newerThanDateTime = newerThanDateTime.ToString(DnaTimeFormat) }; var results = await _coreDbExecution.ExecuteQuery(query, newerThanDateTimeParam); return results; } /// /// Searches for closed indirect loans with detail with closed date greater than the parameter using SQL query. /// Default Included: Graph /// /// /// IEnumerable public async Task> FindClosedWithDetailByPostedDate(DateTime newerThanDateTime) { var query = QueryUtilities.GetQuery(closedIndirectLoanWithDetailByPostedDateQuery); var newerThanDateTimeParam = new { newerThanDateTime = newerThanDateTime.ToString(DnaTimeFormat) }; var results = await _coreDbExecution.ExecuteQuery(query, newerThanDateTimeParam); return results; } public async Task> 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>(endpoint, null, headers, 0); } } }