Files
2026-03-31 14:32:23 -05:00

79 lines
4.6 KiB
C#

using System.Collections.Generic;
using System.Threading.Tasks;
using System;
using Newtonsoft.Json;
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.CoreApiWrapperModel.Constants;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreRequests;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Persons;
using LCU.Library.Internal.CoreApiWrapperLib.CoreDbUtilities;
namespace LCU.Library.Internal.CoreApiWrapperLib.DataAccess
{
public class PersonUserFieldDao : BaseCoreDao, IPersonUserFieldDao
{
private readonly ICoreDbExecution _coreDbExecution;
private readonly CoreConfiguration _coreConfiguration;
private readonly CoreApiConfiguration _coreApiConfiguration;
private const string GetPersonsForCheckHoldsUpdate = "Person/GetPersonsForCheckHoldsUpdate";
private const string DnaTimeFormat = "MM-dd-yyyy HH:mm:ss";
public PersonUserFieldDao(ICoreRequest coreRequest, CoreConfiguration coreConfiguration, ICoreDbExecution coreDbExecution) : base(coreRequest)
{
_coreConfiguration = coreConfiguration;
_coreApiConfiguration = _coreConfiguration.CoreApiConfiguration;
_coreDbExecution = coreDbExecution;
}
public async Task<PersonUserField> UpdatePersonUserField(CoreApiMessage<PersonUserFieldRequest> personUserFieldUpdateRequest,
int personId,
string userFieldId)
{
var strPersonId = JsonConvert.ToString(personId);
var endpoint = HttpUtilities.ReplaceRootParameter(_coreApiConfiguration.CoreEndPointConfiguration.PutPersonUserField,
RequestRootParameters.PersonId,
strPersonId);
endpoint = HttpUtilities.ReplaceRootParameter(endpoint, RequestRootParameters.UserFieldId, userFieldId);
var jsonBody = JsonConvert.SerializeObject(personUserFieldUpdateRequest);
var result = await _coreRequest.PutRequestObject<CoreApiMessage<PersonUserField>>(endpoint, null, jsonBody);
return result?.MessageBody;
}
public async Task<PersonUserField> InsertPersonUserField(CoreApiMessage<PersonUserFieldRequest> personUserFieldRequest,
int personId)
{
var strPersonId = JsonConvert.ToString(personId);
var endpoint = HttpUtilities.ReplaceRootParameter(_coreApiConfiguration.CoreEndPointConfiguration.PersonUserFields,
RequestRootParameters.PersonId,
strPersonId);
var jsonBody = JsonConvert.SerializeObject(personUserFieldRequest);
var result = await _coreRequest.PostRequestObject<CoreApiMessage<PersonUserField>>(endpoint, null, jsonBody);
return result?.MessageBody;
}
public async Task<CoreApiMessage<IEnumerable<PersonUserField>>> FindPersonUserFieldCoreApiResponseByPersonId(CoreRequestParameters coreRequestParameters, int personId)
{
var endpointParameters = HttpUtilities.BuildDictionaryOfNonNullValues(coreRequestParameters);
var endpoint = HttpUtilities.ReplaceRootParameter(_coreApiConfiguration.CoreEndPointConfiguration.PersonUserFields,
RequestRootParameters.PersonId,
JsonConvert.ToString(personId));
return await _coreRequest.GetRequestObject<CoreApiMessage<IEnumerable<PersonUserField>>>(endpoint, endpointParameters);
}
public async Task<IEnumerable<PersonCheckHoldsUserField>> FindPersonsForAtmCheckHolds(DateTime? resetStartDate, DateTime? resetEndDate)
{
var query = QueryUtilities.GetQuery(GetPersonsForCheckHoldsUpdate);
var personUserFieldDateParams = new
{
ResetStartDate = resetStartDate?.ToString(DnaTimeFormat), //to indicate the start and end date to reset user field values
ResetEndDate = resetEndDate?.ToString(DnaTimeFormat)
};
return await _coreDbExecution.ExecuteQuery<PersonCheckHoldsUserField, object>(query, personUserFieldDateParams);
}
}
}