Adding
This commit is contained in:
+111
@@ -0,0 +1,111 @@
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls Core API to search based on any or any number of the PersonNameRequest properties.
|
||||
/// Default Included: Graph
|
||||
/// </summary>
|
||||
/// <param name="coreRequestParameters"></param>
|
||||
/// <param name="personRequest"></param>
|
||||
/// <returns>IEnumerable<Person></returns>
|
||||
public async Task<IEnumerable<Person>> FindByPersonsName(CoreRequestParameters coreRequestParameters, PersonNameRequest personRequest)
|
||||
{
|
||||
var endpointParameters = HttpUtilities.BuildDictionaryOfNonNullValues(coreRequestParameters);
|
||||
var jsonBody = HttpUtilities.BuildJsonOfNonNullProperties(personRequest);
|
||||
var result = await _coreRequest.PostRequestObject<CoreApiMessage<IEnumerable<Person>>>(
|
||||
_coreApiConfiguration.CoreEndPointConfiguration.PersonsQueryName,
|
||||
endpointParameters,
|
||||
jsonBody);
|
||||
return result?.MessageBody;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls Core API to search based on any or any number of the PersonSearchRequest properties.
|
||||
/// Default Included: EmailAddresses, OrgRelationships, PersonInfo, PersonPhonesCard, PostalAddresses
|
||||
/// </summary>
|
||||
/// <param name="coreRequestParameters"></param>
|
||||
/// <param name="personRequest"></param>
|
||||
/// <returns>IEnumerable<Person></returns>
|
||||
public async Task<IEnumerable<Person>> FindByPersonsSearch(CoreRequestParameters coreRequestParameters, PersonSearchRequest personRequest)
|
||||
{
|
||||
var endpointParameters = HttpUtilities.BuildDictionaryOfNonNullValues(coreRequestParameters);
|
||||
var jsonBody = HttpUtilities.BuildJsonOfNonNullProperties(personRequest);
|
||||
var result = await _coreRequest.PostRequestObject<CoreApiMessage<IEnumerable<Person>>>(_coreApiConfiguration.CoreEndPointConfiguration.PersonsQuerySearch,
|
||||
endpointParameters,
|
||||
jsonBody);
|
||||
return result?.MessageBody;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls Core API to search based on MemberAgreementNbrRequest property.
|
||||
/// Default Included: Graph
|
||||
/// </summary>
|
||||
/// <param name="coreRequestParameters"></param>
|
||||
/// <param name="personRequest"></param>
|
||||
/// <returns>Person</returns>
|
||||
public async Task<Person> FindByPersonMemberAgreementNbr(CoreRequestParameters coreRequestParameters, MemberNbrRequest personRequest)
|
||||
{
|
||||
var endpointParameters = HttpUtilities.BuildDictionaryOfNonNullValues(coreRequestParameters);
|
||||
var jsonBody = HttpUtilities.BuildJsonOfNonNullProperties(personRequest);
|
||||
var result = await _coreRequest.PostRequestObject<CoreApiMessage<Person>>(
|
||||
_coreApiConfiguration.CoreEndPointConfiguration.PersonsQueryMemberAgreementNbr,
|
||||
endpointParameters,
|
||||
jsonBody);
|
||||
return result?.MessageBody;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<long>> 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<long, dynamic>(query, queryParameters);
|
||||
}
|
||||
|
||||
public async Task<long> 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<long, dynamic>(query, queryParameters)).Single();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user