public List <LegalCustomerHistory> GetReferralCustomerHistoryUsingApCustomerId(int apCustomerId)
        {
            var myCustomerHistory = new List <LegalCustomerHistory>();

            try
            {
                // Get results from AS database.
                myCustomerHistory = _myIApplicationsRepository.LegalCustomerHistoryRepository.GetFilteredToList(x => x.customerID == apCustomerId);

                //Calculate the corresponding AP customerID
                var latestLegalReferralId = _myIApplicationsRepository.LegalReferredInOutCustomersLegalRepository
                                            .GetFilteredToIQuerable(x => x.CustomerId == apCustomerId).OrderByDescending(x => x.ReferralId)
                                            .FirstOrDefault()?.ReferralId;

                var asCustomerId = _myIApplicationsRepository.ReferralsServiceRepository
                                   .GetFilteredToIQuerable(x => x.ReferralId == latestLegalReferralId).FirstOrDefault()?.CustomerId;

                //Add APCustomerHistory to list and order.
                myCustomerHistory.AddRange(_myIApplicationsRepository.AsCustomerHistoryRepository
                                           .GetFilteredToList(x => x.customerID == asCustomerId).Select(asCustomerHistoryListItem =>
                                                                                                        _myIAutoMapperService.MapLegalCustomerHistory(asCustomerHistoryListItem)).ToList());
                myCustomerHistory = myCustomerHistory.OrderByDescending(x => x.logtime).ToList();
            }
            catch (Exception e)
            {
                _myInLogService.LogError(e, "Method: Querying.Referrals.Services.Applications.Services.AppRepositoryServices.ReferralsService/LegalRepositoryService/" + nameof(GetReferralCustomerHistoryUsingApCustomerId) + ": " + e.Message);
            }

            return(myCustomerHistory);
        }