Helper class that can be used to map country ISO code to a country as well as country to ISO codes.
Syntax
public static class GeoLocationMapping
Example
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);
}
}
}
Inheritance Hierarchy
System.Object
Walter.BOM.Geo.GeoLocationMapping
Requirements
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
See Also