public async Task <PropertyWithAlerts> ExecuteAsync(string propertyReference) { var assetResponse = await _assetGateway.GetById(propertyReference); if (assetResponse == null) { return(null); } var tenureInformation = await _tenureInformationGateway.GetById(assetResponse.Tenure?.Id); var locationAlertListTask = _alertsGateway.GetLocationAlertsAsync(propertyReference); var personAlertListTask = _alertsGateway.GetPersonAlertsAsync(tenureInformation?.TenancyAgreementReference); var residentContactListTask = _residentContactGateway.GetByHouseholdReferenceAsync(tenureInformation?.HouseholdReference); var contactDetailsTask = GetContactDetailsFromNewAPI(tenureInformation?.HouseholdMembers); await Task.WhenAll(locationAlertListTask, personAlertListTask, residentContactListTask, contactDetailsTask); var locationAlertList = locationAlertListTask.Result; var personAlertList = personAlertListTask.Result; var residentContactList = residentContactListTask.Result; var contactDetails = contactDetailsTask.Result; // new API return(new PropertyWithAlerts { PropertyModel = assetResponse.ToDomain(), LocationAlerts = locationAlertList.Alerts, PersonAlerts = personAlertList.Alerts, Tenure = tenureInformation, Contacts = residentContactList, ContactDetails = contactDetails }); }
public async Task <AlertList> ExecuteAsync(string propertyReference) { var propertyAlertList = await _alertsGateway.GetLocationAlertsAsync(propertyReference); var tenureInformation = await _tenureInformationUseCase.GetTenureInformationWithPropertyReference(propertyReference); var personAlertList = await _alertsGateway.GetPersonAlertsAsync(tenureInformation?.TenancyAgreementReference); return(new AlertList { PropertyAlerts = propertyAlertList, PersonAlerts = personAlertList }); }
private async Task <order> CreateOrder(WorkOrder workOrder) { var property = workOrder.Site?.PropertyClass.FirstOrDefault(); var locationAlerts = property != null ? (await _alertsGateway.GetLocationAlertsAsync(property.PropertyReference)).Alerts : new List <Alert>(); var tenureInfo = await _tenureInformationUseCase.GetTenureInformationWithPropertyReference(property?.PropertyReference); var personAlerts = tenureInfo != null ? (await _alertsGateway.GetPersonAlertsAsync(tenureInfo.TenancyAgreementReference)).Alerts : new List <Alert>(); var uniqueCodes = locationAlerts?.Union(personAlerts); var orderComments = @$ "{uniqueCodes.ToCodeString()} {workOrder.DescriptionOfWork}".Truncate(250); var orderCommentsExtended = ($"Property Alerts {locationAlerts?.ToCommentsExtendedString()} " + $"Person Alerts {personAlerts?.ToCommentsExtendedString()}").Truncate(250); var priorityCharacter = workOrder.WorkPriority.PriorityCode.HasValue ? await _sorPriorityGateway.GetLegacyPriorityCode(workOrder.WorkPriority.PriorityCode.Value) : " "; var phoneNumber = workOrder.Customer.Person.Communication.GetPhoneNumber(); return(new order { status = orderStatus.PLANNED, primaryOrderNumber = workOrder.Id.ToString(CultureInfo.InvariantCulture), orderComments = orderComments, contract = workOrder.AssignedToPrimary.ContractorReference, locationID = workOrder.Site?.PropertyClass.FirstOrDefault()?.PropertyReference, priority = priorityCharacter, targetDate = workOrder.WorkPriority.RequiredCompletionDateTime.HasValue ? DrsHelpers.ConvertToDrsTimeZone(workOrder.WorkPriority.RequiredCompletionDateTime.Value) : DateTime.UtcNow, userId = workOrder.AgentEmail ?? workOrder.AgentName, contactName = workOrder.Customer.Name, phone = phoneNumber, orderCommentsExtended = orderCommentsExtended, theLocation = new location { locationId = workOrder.Site?.PropertyClass.FirstOrDefault()?.PropertyReference, name = workOrder.Site?.Name, address1 = workOrder.Site?.PropertyClass.FirstOrDefault()?.Address.AddressLine, postCode = workOrder.Site?.PropertyClass.FirstOrDefault()?.Address.PostalCode, contract = workOrder.AssignedToPrimary.ContractorReference, citizensName = workOrder.Customer.Name }, theBookingCodes = await BuildBookingCodes(workOrder), message = phoneNumber != null && Regex.IsMatch(phoneNumber, @"^(07\d{8,12}|447\d{7,11})$") }); }