private static void ValidateReferralInformationRequestData(ReferralInformationRequest contract) { if (string.IsNullOrWhiteSpace(contract.CustomerId)) { throw new ArgumentException("CustomerId required"); } if (contract.CustomerId.Length > 100) { throw new ArgumentException($"{nameof(contract.CustomerId)} must be less than 100 characters"); } if (string.IsNullOrWhiteSpace(contract.PartnerId)) { throw new ArgumentException("Partner Id required"); } if (contract.PartnerId.Length > 100) { throw new ArgumentException($"{nameof(contract.PartnerId)} must be less than 100 characters"); } if (!string.IsNullOrWhiteSpace(contract.ExternalLocationId) && contract.ExternalLocationId.Length > 100) { throw new ArgumentException($"{nameof(contract.ExternalLocationId)} must be less than 100 characters"); } }
public async Task <ReferralInformationResponse> GetReferralInformationAsync(ReferralInformationRequest contract) { ValidateReferralInformationRequestData(contract); var response = new ReferralInformationResponse { Status = ReferralInformationStatus.OK, Referrals = new List <Domain.Models.Referral>() }; LocationInfoResponse locationInfoResponse = null; if (!string.IsNullOrWhiteSpace(contract.ExternalLocationId)) { locationInfoResponse = await _partnerManagementClient.Locations.GetByExternalId2Async(contract.ExternalLocationId); if (locationInfoResponse == null) { response.Status = ReferralInformationStatus.LocationNotFound; return(response); } } var partnerAndLocationStatus = await _partnerAndLocationHelper.ValidatePartnerInfo(contract.PartnerId, locationInfoResponse); if (partnerAndLocationStatus != PartnerAndLocationStatus.OK) { if (partnerAndLocationStatus == PartnerAndLocationStatus.PartnerNotFound) { response.Status = ReferralInformationStatus.PartnerNotFound; } if (partnerAndLocationStatus == PartnerAndLocationStatus.LocationNotFound) { response.Status = ReferralInformationStatus.LocationNotFound; } return(response); } var customerProfile = await _customerProfileClient.CustomerProfiles.GetByCustomerIdAsync(contract.CustomerId); if (customerProfile.ErrorCode != CustomerProfileErrorCodes.None) { _log.Warning("Could not find customer profile", null, new { contract.CustomerId, customerProfile.ErrorCode }); response.Status = ReferralInformationStatus.CustomerNotFound; return(response); } var referralInfo = await _referralClient.ReferralHotelsApi.GetByEmailAsync( new GetHotelReferralsByEmailRequestModel { Email = customerProfile.Profile.Email, PartnerId = contract.PartnerId, Location = locationInfoResponse?.Id.ToString(), }); foreach (var hotelReferral in referralInfo.HotelReferrals) { var referralContract = await GetProcessedReferral(hotelReferral); if (referralContract == null) { _log.Warning($"Skipped processing referral with Id {hotelReferral.Id} due to technical problem"); continue; } response.Referrals.Add(referralContract); } return(response); }