public async Task<JArray> BySomething(string q, bool IncludeHistorical = false, AddressSearchScope Scope = AddressSearchScope.Local) { JArray PrefetchList = new JArray(); (await Lookup.Data.BySomething(q, IncludeHistorical, Scope)).ToList().ForEach(a => { List<string> Tokens = new List<string>(); Tokens.Add(a.PostCode); Tokens.Add(a.Property); Tokens.Add(a.Street); Tokens.Add(a.Organisation); dynamic o = new JObject(); o.value = a.FullAddress; o.tokens = new JArray(); foreach (var Token in Tokens.Distinct()) { var t = System.Text.RegularExpressions.Regex.Replace(Token, @"[^a-zA-Z0-9]", String.Empty); if (!String.IsNullOrWhiteSpace(t)) { o.tokens.Add(t); } } o.data = JObject.FromObject(a); PrefetchList.Add(o); }); return PrefetchList; }
public async Task<IEnumerable<Address.Models.Address>> ByPostCode(string Id, [FromUri]IEnumerable<string> Classifications, AddressSearchScope Scope = AddressSearchScope.National, bool IncludeHistorical = false, bool PostallyAddressable = true) { if (Classifications == null || Classifications.Count() == 0) { Classifications = new string[] { "Residential" }; } else { // Remove empty entries Classifications = Classifications.Where(c => !string.IsNullOrWhiteSpace(c)); if (Classifications.Contains("All")) { Classifications = null; } } return await Lookup.Data.ByPostCode(Id, IncludeHistorical, Scope, Classifications, PostallyAddressable); }
/// <summary> /// Lookup a list of address details by post code /// </summary> /// <param name="postCode">Post code</param> /// <param name="IncludeHistorical">Include historical properties</param> /// <param name="CheckNational">Include results from AddressBase</param> /// <param name="Scope">The search scope</param> /// <param name="Classifications">Filter by property classification (defaults to Residential) - use "All" to get everything</param> /// <param name="PostallyAddressable">Filter to only postally addressable</param> /// <returns>List of <see cref="AddressDetails" /></returns> public static async Task<IEnumerable<Models.Address>> AddressDetailsByPostCode(string PostCode, bool IncludeHistorical = false, AddressSearchScope Scope = AddressSearchScope.Local, IEnumerable<string> Classifications = null, bool PostallyAddressable = true) { using (var client = GetClient()) { var Url = "2/Lookup/ByPostCode/" + PostCode + "?Scope=" + Scope.ToString() + "&IncludeHistorical=" + IncludeHistorical.ToString() + "&postallyaddressable=" + PostallyAddressable.ToString() + FormatForQueryString("classifications", Classifications); Serilog.Log.Information("Searching for addresses via {0}", Url); var response = client.GetAsync(Url).Result; if (response.IsSuccessStatusCode) { return await response.Content.ReadAsAsync<IEnumerable<Models.Address>>(); } else { return new List<Models.Address>(); } } }
/// <summary> /// Lookup a list of address details by something /// </summary> /// <param name="Query">Query</param> /// <param name="IncludeHistorical">Include historical properties</param> /// <param name="CheckNational">Include results from AddressBase</param> /// <param name="Scope">The search scope</param> /// <param name="Classifications">Filter by property classification (defaults to Residential) - use "All" to get everything</param> /// <param name="PostallyAddressable">Filter to only postally addressable</param> /// <returns>List of <see cref="AddressDetails" /></returns> public static async Task<IEnumerable<Models.Address>> AddressDetailsBySomething(string Query, bool IncludeHistorical = false, AddressSearchScope Scope = AddressSearchScope.Local, IEnumerable<string> Classifications = null, bool PostallyAddressable = true) { using (var client = GetClient()) { var Url = "2/Lookup/BySomething/?Query=" + WebUtility.UrlEncode(Query) + "&Scope=" + Scope.ToString() + "&IncludeHistorical=" + IncludeHistorical.ToString() + "&postallyaddressable=" + PostallyAddressable.ToString() + FormatForQueryString("classifications", Classifications); Serilog.Log.Information("Searching for addresses via {0}", Url); // For some reasone this does't always return if awaited var response = client.GetAsync(Url).Result; if (response.IsSuccessStatusCode) { return await response.Content.ReadAsAsync<IEnumerable<Models.Address>>(); } else { return new List<Models.Address>(); } } }
public static async Task<IEnumerable<Models.Address>> AddressDetailsByUprn(long Uprn, bool IncludeHistorical = false, AddressSearchScope Scope = AddressSearchScope.Local) { return await AddressDetailsByUprn(Uprn); }
public async Task<IEnumerable<Address.Models.Address>> ByUprn(Int64 Uprn, AddressSearchScope Scope = AddressSearchScope.National, bool IncludeHistorical = true) { // Always include historical return await Lookup.Data.ByUprn(Uprn, true, Scope); }
public async Task<IEnumerable<Address.Models.Address>> Nearest(AddressSearchScope Scope = AddressSearchScope.National, double Long = 0, double Lat = 0, double Accuracy = 10) { return await Lookup.Data.FindNearest(Long, Lat, Accuracy, Scope); }