Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update IbanNet dependency in examples [skip ci] #159

Merged
merged 1 commit into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions examples/AspNetCore/AspNetCoreExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
</PropertyGroup>

<ItemGroup Condition="'$(Configuration)' == 'Debug DataAnnotations'">
<PackageReference Include="IbanNet.DataAnnotations" Version="5.3.1" />
<PackageReference Include="IbanNet.DataAnnotations" Version="5.10.0" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)' == 'Debug FluentValidation'">
<PackageReference Include="FluentValidation.AspNetCore" Version="10.3.5" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="10.3.5" />
<PackageReference Include="IbanNet.FluentValidation" Version="5.3.1" />
<PackageReference Include="IbanNet.FluentValidation" Version="5.10.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="IbanNet.DependencyInjection.ServiceProvider" Version="5.3.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.0" />
<PackageReference Include="IbanNet.DependencyInjection.ServiceProvider" Version="5.10.0" />
</ItemGroup>

<ItemGroup>
Expand Down
59 changes: 29 additions & 30 deletions examples/AspNetCore/Controllers/MvcController.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
using ExampleWebApplication.Models;
using AspNetCoreExample.Models;
using IbanNet;
using Microsoft.AspNetCore.Mvc;

namespace ExampleWebApplication.Controllers
namespace AspNetCoreExample.Controllers;

/// <summary>
/// MVC example, showing usage of IbanNet validation.
/// </summary>
public class MvcController : Controller
{
/// <summary>
/// MVC example, showing usage of IbanNet validation.
/// </summary>
public class MvcController : Controller
{
private readonly IIbanParser _parser;
private readonly IIbanParser _parser;

public MvcController(IIbanParser parser)
{
_parser = parser;
}
public MvcController(IIbanParser parser)
{
_parser = parser;
}

// GET
public IActionResult Index()
{
return View();
}
// GET
public IActionResult Index()
{
return View();
}

public IActionResult Save(InputModel model)
{
if (!ModelState.IsValid)
{
return View("Index");
}
public IActionResult Save(InputModel model)
{
if (!ModelState.IsValid)
{
return View("Index");
}

Iban iban = _parser.Parse(model.BankAccountNumber);
// Do something with model...
ModelState.Clear();
model.BankAccountNumber = iban.ToString(IbanFormat.Print);
Iban iban = _parser.Parse(model.BankAccountNumber);
// Do something with model...
ModelState.Clear();
model.BankAccountNumber = iban.ToString(IbanFormat.Print);

return View("Index", model);
}
}
return View("Index", model);
}
}
51 changes: 25 additions & 26 deletions examples/AspNetCore/Controllers/WebApiController.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
using ExampleWebApplication.Models;
using AspNetCoreExample.Models;
using IbanNet;
using Microsoft.AspNetCore.Mvc;

namespace ExampleWebApplication.Controllers
namespace AspNetCoreExample.Controllers;

/// <summary>
/// Web API example, showing usage of IbanNet.
/// </summary>
[Route("api/[controller]")]
public class WebApiController : ControllerBase
{
/// <summary>
/// Web API example, showing usage of IbanNet.
/// </summary>
[Route("api/[controller]")]
public class WebApiController : ControllerBase
{
private readonly IIbanParser _parser;
private readonly IIbanParser _parser;

public WebApiController(IIbanParser parser)
{
_parser = parser;
}
public WebApiController(IIbanParser parser)
{
_parser = parser;
}

[HttpPost]
public IActionResult Save([FromBody] InputModel model)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
[HttpPost]
public IActionResult Save([FromBody] InputModel model)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}

Iban iban = _parser.Parse(model.BankAccountNumber);
// Do something with model...
model.BankAccountNumber = iban.ToString(IbanFormat.Print);
Iban iban = _parser.Parse(model.BankAccountNumber);
// Do something with model...
model.BankAccountNumber = iban.ToString(IbanFormat.Print);

return Ok(model);
}
}
return Ok(model);
}
}
12 changes: 6 additions & 6 deletions examples/AspNetCore/Models/InputModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
#endif
using IbanNet;

namespace ExampleWebApplication.Models
namespace AspNetCoreExample.Models
{
public class InputModel
{
#if !DEBUG_FLUENTVALIDATION
[Required]
[Iban]
[Required]
[Iban(Strict = false)]
#endif
public string BankAccountNumber { get; set; }
}
public string BankAccountNumber { get; set; } = default!;
}

#if DEBUG_FLUENTVALIDATION
public class InputModelValidator : AbstractValidator<InputModel>
Expand All @@ -26,7 +26,7 @@ public InputModelValidator(IIbanValidator ibanValidator)
RuleFor(x => x.BankAccountNumber)
.NotNull()
.NotEmpty()
.Iban(ibanValidator);
.Iban(ibanValidator, strict: false);
}
}
#endif
Expand Down
19 changes: 9 additions & 10 deletions examples/AspNetCore/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using System.Diagnostics;
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace ExampleWebApplication.Pages
namespace AspNetCoreExample.Pages;

public class ErrorModel : PageModel
{
public class ErrorModel : PageModel
{
public string RequestId { get; set; }
public string? RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
2 changes: 1 addition & 1 deletion examples/AspNetCore/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace ExampleWebApplication.Pages
namespace AspNetCoreExample.Pages
{
public class IndexModel : PageModel
{
Expand Down
51 changes: 25 additions & 26 deletions examples/AspNetCore/Pages/RazorPage.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
using ExampleWebApplication.Models;
using AspNetCoreExample.Models;
using IbanNet;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace ExampleWebApplication.Pages
namespace AspNetCoreExample.Pages;

/// <summary>
/// Razor Page example, showing usage of IbanNet.
/// </summary>
public class RazorPageModel : PageModel
{
/// <summary>
/// Razor Page example, showing usage of IbanNet.
/// </summary>
public class RazorPageModel : PageModel
{
private readonly IIbanParser _parser;
private readonly IIbanParser _parser;

public RazorPageModel(IIbanParser parser)
{
_parser = parser;
}
public RazorPageModel(IIbanParser parser)
{
_parser = parser;
}

[BindProperty]
public InputModel Model { get; set; }
[BindProperty]
public InputModel Model { get; set; } = default!;

public IActionResult OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
public IActionResult OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}

Iban iban = _parser.Parse(Model.BankAccountNumber);
// Do something with model...
Model.BankAccountNumber = iban.ToString(IbanFormat.Print);
Iban iban = _parser.Parse(Model.BankAccountNumber);
// Do something with model...
Model.BankAccountNumber = iban.ToString(IbanFormat.Print);

return Page();
}
}
return Page();
}
}
2 changes: 1 addition & 1 deletion examples/AspNetCore/Pages/WebApi.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace ExampleWebApplication.Pages
namespace AspNetCoreExample.Pages
{
public class WebApiModel : PageModel
{
Expand Down
6 changes: 3 additions & 3 deletions examples/AspNetCore/Pages/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - ExampleWebApplication</title>
<title>@ViewData["Title"] - AspNetCoreExample</title>

<environment include="Development">
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
Expand All @@ -28,7 +28,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a asp-page="/Index" class="navbar-brand">ExampleWebApplication</a>
<a asp-page="/Index" class="navbar-brand">AspNetCoreExample</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
Expand All @@ -43,7 +43,7 @@
@RenderBody()
<hr />
<footer>
<p>&copy; 2017 - ExampleWebApplication</p>
<p>&copy; 2017 - AspNetCoreExample</p>
</footer>
</div>

Expand Down
4 changes: 2 additions & 2 deletions examples/AspNetCore/Pages/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@using ExampleWebApplication
@namespace ExampleWebApplication.Pages
@using AspNetCoreExample
@namespace AspNetCoreExample.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
22 changes: 10 additions & 12 deletions examples/AspNetCore/Program.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;

namespace ExampleWebApplication
namespace AspNetCoreExample;

public static class Program
{
public class Program
public static void Main(string[] args)
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}

public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
BuildWebHost(args).Run();
}

private static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
Loading