protected void OnLocationLoaded(SearchCriteria criteria) { var criteriaLocation = criteria as ISearchCriteriaLocation; if (criteriaLocation == null) { return; } // "255" is reserved for "anywhere" if (criteriaLocation.CountryId == 255) { return; } // Old alerts store location in different ways so try to use them. if (criteriaLocation.Area != null) { var area = _locationQuery.GetGeographicalArea(criteriaLocation.Area.Value, true); criteriaLocation.Location = new LocationReference(area); return; } // Country, default to Australia if not found. var country = criteriaLocation.CountryId != null ? _locationQuery.GetCountry(criteriaLocation.CountryId.Value) : null; var postcode = criteriaLocation.Postcode; var state = criteriaLocation.State; var location = criteriaLocation.LocationText; if (!string.IsNullOrEmpty(postcode)) { // If only the postcode is set then use that. if (string.IsNullOrEmpty(state) && string.IsNullOrEmpty(location)) { var postalCode = _locationQuery.GetPostalCode(country ?? _locationQuery.GetCountry("Australia"), criteriaLocation.Postcode); if (postalCode != null) { criteriaLocation.Location = new LocationReference(postalCode.Locality); return; } } } if (!string.IsNullOrEmpty(criteriaLocation.State)) { // If only the state is set then use that. if (string.IsNullOrEmpty(postcode) && string.IsNullOrEmpty(location)) { var countrySubdivision = _locationQuery.GetCountrySubdivision(country ?? _locationQuery.GetCountry("Australia"), criteriaLocation.State); if (countrySubdivision != null) { criteriaLocation.Location = new LocationReference(countrySubdivision); return; } } } // Standard way. if (country == null && string.IsNullOrEmpty(postcode) && string.IsNullOrEmpty(state) && string.IsNullOrEmpty(location)) { return; } // Put in everything. if (string.IsNullOrEmpty(location)) { location = string.Empty; } if (!string.IsNullOrEmpty(postcode)) { location += " " + postcode; } if (!string.IsNullOrEmpty(state)) { location += " " + state; } criteriaLocation.Location = _locationQuery.ResolveLocation(country ?? _locationQuery.GetCountry("Australia"), location); }