diff --git a/Logic/Structure/Geography.cs b/Logic/Structure/Geography.cs index a5badcec..871470d9 100644 --- a/Logic/Structure/Geography.cs +++ b/Logic/Structure/Geography.cs @@ -131,6 +131,33 @@ namespace Swarmops.Logic.Structure return false; } + public Country Country + { + get + { + Countries countries = Countries.All; + Dictionary geoLookup = new Dictionary(); + + foreach (Country country in countries) + { + geoLookup[country.GeographyId] = country; + } + + Geography iterator = this; + while (!geoLookup.ContainsKey (iterator.Identity) && iterator.ParentGeographyId != 0) + { + iterator = iterator.Parent; + } + + if (geoLookup.ContainsKey (iterator.Identity)) + { + return geoLookup[iterator.Identity]; + } + + return null; // no country - we're probably a geography above the country line + } + } + public Geographies ThisAndBelow() { return Geographies.FromArray (GeographyCache.GetGeographyTree (Identity));