We will continuing using previous tutorial "Logistics" and add validator to show how to use this feature

## Add Validation to ShippingGuide

Open your Visual Code and login. Open object **ShippingGuide**.

Add the following property that will identify the Country that vendor is associated:

Add to the existing property "vendorTaxId" the following validation rule:

  • Validate Tax Id by country

Find property **vendorTaxId** and bellow the property and the following code lines

  • **_value** reference the property in the scope.

  • **_this** reference object in the scope.

  • **_arguments** array of arguments that can be passes do the Validation function

The Validation will use the country value passed in the arguments [arguments[0]) or if null, the value of the property **vendorCountry**

The result of the validation will be structured:

  • **IsValid** Boolean

  • **ErrorMessage** error validation message if **IsValid** is False

The full code of the **ShippingGuide** have to be:

## Download & Update Nuget packages

Build and download Nuget packages. _On build file ("Logistics") select "Download" (choosing directory where you want to download the files)_

Open your Visual Studio and the project previous created "Tutorial - Logistics".

Update the 2 Nuget packages on your Visual Studio project. _note: before updating, on command prompt (cmd), PowerShell or Package Manager Console of Visual Studio execute the command bellow_

_This clean nuget cache of the system, ensuring that version want is running_

## Use of Validaters

On class "Program.cs" add the following function:

Example you are setting different values for the vendor tax id (property: vendorTaxId), using the country of the vendor or passing this value as argument and calling Validation function and printing the results.

Add call on "main" to the function that you have create.

Run the program and in the command prompt you should see the messages of the validations performed.


The solution is available: [Source](🔗)