Implemented webmethods to extract geography data from an installation
This commit is contained in:
@@ -34,7 +34,7 @@ namespace Activizr.Database
|
||||
|
||||
#region Record reading - SELECT statements
|
||||
|
||||
public BasicPostalCode[] GetPostalCodes(string countryCode)
|
||||
public BasicPostalCode[] GetPostalCodesForCountry (string countryCode)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
|
||||
@@ -138,7 +138,7 @@ namespace Activizr.Database
|
||||
}
|
||||
|
||||
|
||||
public BasicCity GetCityByName (string cityName, int countryId)
|
||||
public BasicCity GetCityByName(string cityName, int countryId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
@@ -158,8 +158,29 @@ namespace Activizr.Database
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BasicCity[] GetCitiesByName (string cityName, int countryId)
|
||||
|
||||
public BasicCity GetCityByName(string cityName, string countryCode)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SELECT " + cityFieldSequence + " WHERE CityName='" + cityName.Replace("'", "''") + "' AND CountryCode='" + countryCode.ToUpperInvariant().Replace("'", "''") + "'",
|
||||
connection);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
return ReadCityFromDataReader(reader);
|
||||
}
|
||||
|
||||
throw new ArgumentException("No such CityName: " + cityName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BasicCity[] GetCitiesByName(string cityName, int countryId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
@@ -184,5 +205,30 @@ namespace Activizr.Database
|
||||
}
|
||||
}
|
||||
|
||||
public BasicCity[] GetCitiesByCountry(string countryCode)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SELECT " + cityFieldSequence + " WHERE CountryCode='" + countryCode.ToUpperInvariant().Replace("'", "''") + "'",
|
||||
connection);
|
||||
List<BasicCity> result = new List<BasicCity>();
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
result.Add(ReadCityFromDataReader(reader));
|
||||
while (reader.Read())
|
||||
{
|
||||
result.Add(ReadCityFromDataReader(reader));
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
throw new ArgumentException("Cities not in place yet for country: " + countryCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -196,6 +196,8 @@
|
||||
<Compile Include="Governance\MotionAmendments.cs" />
|
||||
<Compile Include="Governance\Motions.cs" />
|
||||
<Compile Include="Structure\OrganizationParameters.cs" />
|
||||
<Compile Include="Structure\PostalCode.cs" />
|
||||
<Compile Include="Structure\PostalCodes.cs" />
|
||||
<Compile Include="Structure\UptakeGeography.cs" />
|
||||
<Compile Include="Support\ActivistEvents.cs" />
|
||||
<Compile Include="Support\Imagery.cs" />
|
||||
|
||||
@@ -40,5 +40,9 @@ namespace Activizr.Logic.Structure
|
||||
return FromArray(PirateDb.GetDatabase().GetCitiesByName(cityName, countryId));
|
||||
}
|
||||
|
||||
public static Cities ForCountry (string countryCode)
|
||||
{
|
||||
return FromArray(PirateDb.GetDatabase().GetCitiesByCountry (countryCode));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using Activizr.Basic.Types;
|
||||
using Activizr.Database;
|
||||
|
||||
namespace Activizr.Logic.Structure
|
||||
{
|
||||
[Serializable]
|
||||
public class City : BasicCity
|
||||
{
|
||||
private City (BasicCity basic)
|
||||
@@ -26,5 +28,9 @@ namespace Activizr.Logic.Structure
|
||||
return FromBasic(PirateDb.GetDatabase().GetCityByName(cityName, countryId));
|
||||
}
|
||||
|
||||
public static City FromName (string cityName, string countryCode)
|
||||
{
|
||||
return FromBasic(PirateDb.GetDatabase().GetCityByName(cityName, countryCode));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Activizr.Basic.Types;
|
||||
|
||||
namespace Activizr.Logic.Structure
|
||||
{
|
||||
[Serializable]
|
||||
public class PostalCode: BasicPostalCode
|
||||
{
|
||||
public PostalCode (BasicPostalCode basic):
|
||||
base (basic)
|
||||
{
|
||||
// constructor
|
||||
}
|
||||
|
||||
static public PostalCode FromBasic (BasicPostalCode basic)
|
||||
{
|
||||
return new PostalCode(basic);
|
||||
}
|
||||
|
||||
public Country Country
|
||||
{
|
||||
get { return Country.FromCode(this.CountryCode); }
|
||||
}
|
||||
|
||||
public City City
|
||||
{
|
||||
get { return City.FromName(this.CityName, this.CountryCode); }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Activizr.Basic.Types;
|
||||
using Activizr.Database;
|
||||
|
||||
namespace Activizr.Logic.Structure
|
||||
{
|
||||
[Serializable]
|
||||
public class PostalCodes: List<PostalCode>
|
||||
{
|
||||
public static PostalCodes FromArray(BasicPostalCode[] array)
|
||||
{
|
||||
var result = new PostalCodes { Capacity = (array.Length * 11 / 10) };
|
||||
|
||||
foreach (BasicPostalCode basic in array)
|
||||
{
|
||||
result.Add(PostalCode.FromBasic(basic));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static PostalCodes ForCountry (string countryCode)
|
||||
{
|
||||
return FromArray(PirateDb.GetDatabase().GetPostalCodesForCountry (countryCode));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,16 @@ public class GetGeographyData : System.Web.Services.WebService {
|
||||
return Countries.GetInUse();
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
public Cities GetCitiesForCountry (string countryCode)
|
||||
{
|
||||
return Cities.ForCountry(countryCode);
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
public PostalCodes GetPostalCodesForCountry (string countryCode)
|
||||
{
|
||||
return PostalCodes.ForCountry(countryCode);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user