public static class GeoLocationMapping
public static class GeoLocationMapping
This class contains quite a few utility classes that make it easy to validate is a GeoLocation is a given county or region and the association between regions and countries.
Perhaps the most central method is to convert 2letter ISO codes to GeoLocations TryGetValue(ReadOnlySpan<Char>,GeoLocation). However the list does not stop there and take some time to go over the other methods available.
The bellow sample makes use of the County being of type GeoLocation. and uses that property to test if EU tax is applicable and if so validate if the VAT identifier is belonging to the company name provided. This sample uses the location provided by the firewall framework using NuGet package Walter.Web.FireWall This code is overly simplified but demonstrate how you could use this feature.
The method used to validate European value added tax (VAT) is from NuGet Package Walter.Vat and allows the validation of VAT data without making use of paid subscription services.
[HttpPost] [ValidateAntiForgeryToken] public async Task<IActionResult> ProcessOrder(Order model) { if (!ModelState.IsValid) return View(model); if (model.Country.IsInTheEuropeanUnion()) { var vies = await Walter.Vat.EuropeanVatInformationQuery.GetAsync(model.VATNumber).ConfigureAwait(false); if (!vies.IsValid || !vies.CompanyName.Equals(model.CompanyName, StringComparison.OrdinalIgnoreCase)) { if (!vies.IsValid) { if (vies.Exception is null) { _logger?.Lazy().LogWarning(vies.Exception ,"Query European VAT failed with a for {vat} in {country}" , model.VATNumber , model.Country); } else { _logger?.Lazy().LogWarning(vies.Exception, "Query European VAT failed with a {exception} exception error {message}" , vies.Exception.GetType().Name , vies.Exception.Message); } ModelState.AddModelError(nameof(model.VATNumber) , "The VAT number is not valid"); } if (!vies.CompanyName.Equals(model.CompanyName, StringComparison.OrdinalIgnoreCase)) { ModelState.AddModelError(nameof(model.VATNumber) , $"The VAT ID provided is belongs to another company than the one you specified, did you enter the wrong ID?"); if (vies.CompanyName.Contains(model.CompanyName, StringComparison.OrdinalIgnoreCase)) { ModelState.AddModelError(nameof(model.CompanyName) , $"The VAT number provided is belongs to {vies.CompanyName}, this sounds like {model.CompanyName} but you should update it to avoid complications."); } else { ModelState.AddModelError(nameof(model.CompanyName) , $"The VAT number provided is belongs to {vies.CompanyName} did you provide the wrong name?"); } } return View(model); } } }
System.Object
Walter.BOM.Geo.GeoLocationMapping
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2