using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels;
using LCU.Library.Internal.CoreApiWrapperLib.Utilities;
using LCU.Library.Internal.CoreApiWrapperLib.Configuration;
using LCU.Library.Internal.CoreApiWrapperLib.CoreApiUtilities;
using LCU.Library.Internal.CoreApiWrapperLib.CoreDbUtilities;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Persons;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreRequests;
namespace LCU.Library.Internal.CoreApiWrapperLib.DataAccess
{
public class PersonDao : BaseCoreDao, IPersonDao
{
private const string PersonByNameLikeCount = "Person/PersonByNameLikeCount";
private const string PersonNumberByNameLikeQuery = "Person/PersonNumberByNameLikeQuery";
private readonly ICoreDbExecution _coreDbExecution;
private readonly CoreConfiguration _coreConfiguration;
private readonly CoreApiConfiguration _coreApiConfiguration;
public PersonDao(ICoreRequest coreRequest,
ICoreDbExecution coreDbExecution,
CoreConfiguration coreConfiguration)
: base(coreRequest)
{
_coreConfiguration = coreConfiguration;
_coreApiConfiguration = _coreConfiguration.CoreApiConfiguration;
_coreDbExecution = coreDbExecution;
}
///
/// Calls Core API to search based on any or any number of the PersonNameRequest properties.
/// Default Included: Graph
///
///
///
/// IEnumerable
public async Task> FindByPersonsName(CoreRequestParameters coreRequestParameters, PersonNameRequest personRequest)
{
var endpointParameters = HttpUtilities.BuildDictionaryOfNonNullValues(coreRequestParameters);
var jsonBody = HttpUtilities.BuildJsonOfNonNullProperties(personRequest);
var result = await _coreRequest.PostRequestObject>>(
_coreApiConfiguration.CoreEndPointConfiguration.PersonsQueryName,
endpointParameters,
jsonBody);
return result?.MessageBody;
}
///
/// Calls Core API to search based on any or any number of the PersonSearchRequest properties.
/// Default Included: EmailAddresses, OrgRelationships, PersonInfo, PersonPhonesCard, PostalAddresses
///
///
///
/// IEnumerable
public async Task> FindByPersonsSearch(CoreRequestParameters coreRequestParameters, PersonSearchRequest personRequest)
{
var endpointParameters = HttpUtilities.BuildDictionaryOfNonNullValues(coreRequestParameters);
var jsonBody = HttpUtilities.BuildJsonOfNonNullProperties(personRequest);
var result = await _coreRequest.PostRequestObject>>(_coreApiConfiguration.CoreEndPointConfiguration.PersonsQuerySearch,
endpointParameters,
jsonBody);
return result?.MessageBody;
}
///
/// Calls Core API to search based on MemberAgreementNbrRequest property.
/// Default Included: Graph
///
///
///
/// Person
public async Task FindByPersonMemberAgreementNbr(CoreRequestParameters coreRequestParameters, MemberNbrRequest personRequest)
{
var endpointParameters = HttpUtilities.BuildDictionaryOfNonNullValues(coreRequestParameters);
var jsonBody = HttpUtilities.BuildJsonOfNonNullProperties(personRequest);
var result = await _coreRequest.PostRequestObject>(
_coreApiConfiguration.CoreEndPointConfiguration.PersonsQueryMemberAgreementNbr,
endpointParameters,
jsonBody);
return result?.MessageBody;
}
public async Task> GetPersonNumbersByNameLike(string firstName, string middleName, string lastName, int limit)
{
var query = QueryUtilities.GetQuery(PersonNumberByNameLikeQuery);
var queryParameters = new {
firstName = firstName?.ToLowerInvariant(),
middleName = middleName?.ToLowerInvariant(),
lastName = lastName?.ToLowerInvariant(),
limit
};
return await _coreDbExecution.ExecuteQuery(query, queryParameters);
}
public async Task CountPersonsByNameLike(string firstName, string middleName, string lastName)
{
var query = QueryUtilities.GetQuery(PersonByNameLikeCount);
var queryParameters = new {
firstName = firstName?.ToLowerInvariant(),
middleName = middleName?.ToLowerInvariant(),
lastName = lastName?.ToLowerInvariant()
};
return (await _coreDbExecution.ExecuteQuery(query, queryParameters)).Single();
}
}
}