From 35ed03695e1b6ddf3c3ed6476743d16d22235885 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sat, 13 Dec 2014 21:49:21 +0100 Subject: [PATCH] Added flexible postal code lookup --- Logic/Swarm/Person.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Logic/Swarm/Person.cs b/Logic/Swarm/Person.cs index cdfa9947..f36a934b 100644 --- a/Logic/Swarm/Person.cs +++ b/Logic/Swarm/Person.cs @@ -529,7 +529,22 @@ namespace Swarmops.Logic.Swarm Cities cities = Cities.FromPostalCode (PostalCode, base.CountryId); City city = null; - if (cities.Count == 0) + if (cities.Count == 0 && PostalCode.Length > 3) + { + // try shortening the postal code - like NL dataset - and see if we find anything + + for (int shortening = 1; shortening <= 3; shortening++) + { + cities = Cities.FromPostalCode (PostalCode.Substring (0, PostalCode.Length - shortening), + base.CountryId); + if (cities.Count > 0) + { + break; + } + } + } + + if (cities.Count == 0) // still no hit? Move on to getting city by name { try {