121 lines
4.6 KiB
C#
121 lines
4.6 KiB
C#
using LCU.Library.Internal.CoreApiWrapperLib.DataAccess;
|
|
using LCU.Library.Internal.CoreApiWrapperModel.Constants;
|
|
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels;
|
|
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreRequests;
|
|
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Organizations;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using LCU.Library.Internal.Exceptions;
|
|
using Serilog;
|
|
using System.Linq;
|
|
|
|
namespace LCU.Api.Internal.CoreApiWrapper.Services
|
|
{
|
|
public class OrganizationService : IOrganizationService
|
|
{
|
|
private readonly IOrganizationDao _organizationDao;
|
|
|
|
public OrganizationService(IOrganizationDao organizationDao)
|
|
{
|
|
_organizationDao = organizationDao;
|
|
}
|
|
|
|
public async Task<Organization> GetMemberByMemberAgreeNbr(long memberAgreeNbr)
|
|
{
|
|
var listOfIncludes = new List<string>
|
|
{
|
|
RequestIncludeConstants.AllAddresses
|
|
};
|
|
var coreRequestParameters = new CoreRequestParameters(listOfIncludes);
|
|
var organizationRequest = new MemberNbrRequest
|
|
{
|
|
MemberNbr = memberAgreeNbr,
|
|
};
|
|
|
|
return await GetOrganizationByMemberNumber(coreRequestParameters, organizationRequest);
|
|
}
|
|
|
|
private async Task<Organization> GetOrganizationByMemberNumber(CoreRequestParameters coreRequestParameters, MemberNbrRequest organizationRequest)
|
|
{
|
|
try
|
|
{
|
|
return await _organizationDao.FindOrganizationByMemberAgreeNbr(coreRequestParameters, organizationRequest);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var message = $"There was an issue finding organization by Member Agreement Number. Exception Message: {ex.Message}";
|
|
Log.Error(ex, message);
|
|
throw new ServiceException(message);
|
|
}
|
|
}
|
|
|
|
public async Task<IEnumerable<Organization>> GetOrganizationByOrganizationNumber(long organizationNumber)
|
|
{
|
|
var coreRequestParameters = new CoreRequestParameters();
|
|
var organizationSearchRequest = new OrganizationSearchRequest
|
|
{
|
|
OrgNbr = organizationNumber
|
|
};
|
|
|
|
return await GetOrganizationBySearch(coreRequestParameters, organizationSearchRequest);
|
|
}
|
|
|
|
public async Task<IEnumerable<Organization>> GetOrganizationByName(string name)
|
|
{
|
|
var coreRequestParameters = new CoreRequestParameters();
|
|
var organizationSearchRequest = new OrganizationSearchRequest
|
|
{
|
|
OrgName = name
|
|
};
|
|
|
|
return await GetOrganizationBySearch(coreRequestParameters, organizationSearchRequest);
|
|
}
|
|
|
|
public async Task<long> CountOrganizationNumbersByName(string name)
|
|
{
|
|
try
|
|
{
|
|
return await _organizationDao.CountOrganizationNumbersByName(name);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var message = $"There was an issue counting organization by name. Exception Message: {ex.Message}";
|
|
Log.Error(ex, message);
|
|
throw new ServiceException(message);
|
|
}
|
|
}
|
|
|
|
|
|
public async Task<IEnumerable<Organization>> GetOrganizationByNameLike(string name, int? limit = null)
|
|
{
|
|
try
|
|
{
|
|
var orgNumbers = await _organizationDao.FindOrganizationNumbersByNameSearch(name, limit ?? 1000);
|
|
var organizations = await Task.WhenAll(orgNumbers.Select(GetOrganizationByOrganizationNumber));
|
|
|
|
return organizations.SelectMany(o => o);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var message = $"There was an issue finding organization by name. Exception Message: {ex.Message}";
|
|
Log.Error(ex, message);
|
|
throw new ServiceException(message);
|
|
}
|
|
}
|
|
|
|
private async Task<IEnumerable<Organization>> GetOrganizationBySearch(CoreRequestParameters coreRequestParameters, OrganizationSearchRequest searchRequest)
|
|
{
|
|
try
|
|
{
|
|
return await _organizationDao.FindByOrganizationsSearch(coreRequestParameters, searchRequest);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var message = $"There was an issue finding organizations by Search - OrgNbr: {searchRequest.OrgNbr}, OrgName: {searchRequest.OrgName}";
|
|
Log.Error(ex, message);
|
|
throw new ServiceException(message);
|
|
}
|
|
}
|
|
}
|
|
} |