public EmployerRecord ToEmployerRecord(long userId = 0) { OrganisationAddress address = null; if (userId > 0) { address = UserOrganisations.FirstOrDefault(uo => uo.UserId == userId)?.Address; } if (address == null) { address = GetLatestAddress(); } if (address == null) { return(new EmployerRecord { OrganisationId = OrganisationId, SectorType = SectorType, OrganisationName = OrganisationName, NameSource = GetName()?.Source, EmployerReference = EmployerReference, DateOfCessation = DateOfCessation, CompanyNumber = CompanyNumber, SicSectors = GetSicSectorsString(null, ",<br/>"), SicCodeIds = GetSicCodeIdsString(), SicSource = GetSicSource(), RegistrationStatus = GetRegistrationStatus(), References = OrganisationReferences.ToDictionary( r => r.ReferenceName, r => r.ReferenceValue, StringComparer.OrdinalIgnoreCase) }); } return(new EmployerRecord { OrganisationId = OrganisationId, SectorType = SectorType, OrganisationName = OrganisationName, NameSource = GetName()?.Source, EmployerReference = EmployerReference, DateOfCessation = DateOfCessation, CompanyNumber = CompanyNumber, SicSectors = GetSicSectorsString(null, ",<br/>"), SicCodeIds = GetSicCodeIdsString(), SicSource = GetSicSource(), ActiveAddressId = address.AddressId, AddressSource = address.Source, Address1 = address.Address1, Address2 = address.Address2, Address3 = address.Address3, City = address.TownCity, County = address.County, Country = address.Country, PostCode = address.GetPostCodeInAllCaps(), PoBox = address.PoBox, IsUkAddress = address.IsUkAddress, RegistrationStatus = GetRegistrationStatus(), References = OrganisationReferences.ToDictionary( r => r.ReferenceName, r => r.ReferenceValue, StringComparer.OrdinalIgnoreCase) }); }