Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sulmar/sulmar.aspnetcore.routing.routeconstraints

Route constraints for validation of Polish NIP, PESEL, REGON for .NET 5
https://github.com/sulmar/sulmar.aspnetcore.routing.routeconstraints

netcore5

Last synced: 1 day ago
JSON representation

Route constraints for validation of Polish NIP, PESEL, REGON for .NET 5

Awesome Lists containing this project

README

        

# Sulmar.AspNetCore.Routing.RouteConstraints
Route constraints for validation of Polish NIP, PESEL, REGON for .NET 5

## Get Started
RouteConstraints can be installed using the Nuget package manager or the dotnet CLI.

~~~
Install-Package Sulmar.AspNetCore.Routing.RouteConstraints
~~~

~~~
dotnet add package Sulmar.AspNetCore.Routing.RouteConstraints
~~~

## Usage

### Register

- PESEL
~~~ csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddPeselConstraint();
}
~~~

- REGON
~~~ csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddRegonConstraint();
}
~~~

- NIP

~~~ csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddNipConstraint();
}
~~~

- or all together
~~~ csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddPolishConstraints();
}
~~~

### Add Route Constraint

- PESEL
~~~ csharp
// GET api/customers/{number}
[HttpGet("{number:pesel}")]
public ActionResult GetByPesel(string number)
{
var customer = customerService.GetByPesel(number);

if (customer == null)
return NotFound();

return Ok(customer);
}
~~~

- REGON
~~~ csharp
// GET api/customers/{number}
[HttpGet("{number:regon}")]
public ActionResult GetByRegon(string number)
{
var customer = customerService.GetByRegon(number);

if (customer == null)
return NotFound();

return Ok(customer);
}
~~~

- NIP
~~~ csharp
// GET api/customers/{number}
[HttpGet("{number:nip}")]
public ActionResult GetByNip(string number)
{
var customer = customerService.GetByNip(number);

if (customer == null)
return NotFound();

return Ok(customer);
}
~~~