Added 'Country' property to Geography

This commit is contained in:
Rick Falkvinge
2015-06-12 17:23:45 +02:00
parent 9aaf3f367d
commit 5d9a5772ba
+27
View File
@@ -131,6 +131,33 @@ namespace Swarmops.Logic.Structure
return false;
}
public Country Country
{
get
{
Countries countries = Countries.All;
Dictionary<int, Country> geoLookup = new Dictionary<int, Country>();
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));