Files
monorepo/LCU.Api.Internal.CoreApiWrapper/LCU.Api.Internal.CoreApiWrapper/Services/PropertyService.cs
T
2026-03-31 14:32:23 -05:00

71 lines
2.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Serilog;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels;
using LCU.Library.Internal.CoreApiWrapperLib.DataAccess;
using LCU.Library.Internal.CoreApiWrapperModel.Constants;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Properties;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreRequests;
namespace LCU.Api.Internal.CoreApiWrapper.Services
{
public class PropertyService : IPropertyService
{
private readonly IPropertyDao _propertyDao;
private readonly IAccountService _accountService;
public PropertyService(IPropertyDao propertyDao, IAccountService accountService)
{
_propertyDao = propertyDao;
_accountService = accountService;
}
public async Task<IEnumerable<Property>> GetAccountProperties(long accountNumber)
{
try
{
var listOfIncludes = new List<string>()
{
RequestIncludeConstants.Collateral
};
var coreRequestParameters = new CoreRequestParameters(listOfIncludes);
var request = new AcctNbrRequest()
{
AcctNbr = accountNumber
};
var account = await _accountService.GetAccountDetails(coreRequestParameters, request);
List<Property> properties = new List<Property>();
foreach (var accountProperties in account.Properties)
{
var property = await GetProperty(accountProperties.PropertyNumber);
if (property != null)
{
properties.Add(property);
}
}
return properties;
}
catch (Exception ex)
{
Log.Warning(ex, $"There was an issue finding accounts properties.");
throw;
}
}
public async Task<Property> GetProperty(long propertyNumber)
{
try
{
return await _propertyDao.FindProperty(propertyNumber);
}
catch (Exception ex)
{
Log.Warning(ex, $"There was an issue finding property by propertyNumber. PropertyNumber: {propertyNumber}");
throw;
}
}
}
}