private async Task AssignPrimaryContactToOrganisation(CreateEpaOrganisationContactRequest primaryContact, string organisationId) { if (primaryContact != null && !string.IsNullOrEmpty(organisationId)) { var primaryContactId = Guid.Empty; var assessorContact = await _apiClient.GetEpaContactByEmail(primaryContact.Email); if (assessorContact is null) { _logger.LogInformation($"Creating a new primary contact ({primaryContact.Email}) for {organisationId}"); var validationResponse = await _assessorValidationService.ValidateNewContactRequest(primaryContact); if (!validationResponse.IsValid) { _logger.LogWarning($"Cannot create new primary contact in assessor for {organisationId}. Validation errors: {validationResponse.Errors.Select(err => err.ErrorMessage)}"); } else { //Create a new contact in assessor table, //Assumption is that this user will need to have an account created in aslogon too //And then when they login the signinid etc wll get populated as it does for existing users var id = await _apiClient.CreateEpaContact(primaryContact); if (Guid.TryParse(id, out primaryContactId)) { _logger.LogInformation($"Contact created successfully - {primaryContactId}"); } } } else { _logger.LogInformation($"Primary contact ({primaryContact.Email}) already exists"); primaryContactId = assessorContact.Id; } if (primaryContactId != Guid.Empty) { _logger.LogInformation($"Associating primary contact ({primaryContact.Email}) to organisation {organisationId}"); var request = new AssociateEpaOrganisationWithEpaContactRequest { ContactId = primaryContactId, OrganisationId = organisationId, ContactStatus = ContactStatus.Live, MakePrimaryContact = true, AddDefaultRoles = true, AddDefaultPrivileges = false }; await _apiClient.AssociateOrganisationWithEpaContact(request); } } }