Na most egy validator is beköszönt
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
using FluentValidation.AspNetCore;
|
||||
using FluentValidation;
|
||||
|
||||
namespace WorkFlowCheck.Web.Validators
|
||||
{
|
||||
public static class FluentValidationConfig
|
||||
{
|
||||
public static IServiceCollection AddFluentValidationSetup(this IServiceCollection services)
|
||||
{
|
||||
services.AddFluentValidationAutoValidation();
|
||||
services.AddFluentValidationClientsideAdapters(); // ha valaha szeretnél client-side-t is
|
||||
|
||||
// Itt regisztrálod a validátorokat – automatikusan az adott assembly-ből
|
||||
services.AddValidatorsFromAssembly(typeof(FluentValidationConfig).Assembly);
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using FluentValidation;
|
||||
using WorkFlowCheck.Common.DTO;
|
||||
|
||||
namespace WorkFlowCheck.Web.Validators
|
||||
{
|
||||
public class UserDTOValidator : AbstractValidator<UserDTO>
|
||||
{
|
||||
public UserDTOValidator()
|
||||
{
|
||||
RuleFor(x => x.UserName)
|
||||
.NotEmpty().WithMessage("A felhasználónév kötelező.");
|
||||
|
||||
RuleFor(x => x.FirstName)
|
||||
.NotEmpty().WithMessage("A keresztnév kötelező.");
|
||||
|
||||
RuleFor(x => x.LastName)
|
||||
.NotEmpty().WithMessage("A vezetéknév kötelező.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user