28 lines
1.0 KiB
C#
28 lines
1.0 KiB
C#
|
|
using FluentValidation;
|
||
|
|
|
||
|
|
namespace SIGCM2.Application.Roles.Update;
|
||
|
|
|
||
|
|
public sealed class UpdateRolCommandValidator : AbstractValidator<UpdateRolCommand>
|
||
|
|
{
|
||
|
|
private const int NombreMaxLength = 60;
|
||
|
|
private const int DescripcionMaxLength = 250;
|
||
|
|
|
||
|
|
public UpdateRolCommandValidator()
|
||
|
|
{
|
||
|
|
// Codigo is taken from the URL route — we don't re-validate format here,
|
||
|
|
// but we require it to be non-empty so handler always has a target to match.
|
||
|
|
RuleFor(x => x.Codigo)
|
||
|
|
.NotEmpty().WithMessage("El código es requerido.");
|
||
|
|
|
||
|
|
RuleFor(x => x.Nombre)
|
||
|
|
.NotEmpty().WithMessage("El nombre es requerido.")
|
||
|
|
.MaximumLength(NombreMaxLength)
|
||
|
|
.WithMessage($"El nombre no puede superar los {NombreMaxLength} caracteres.");
|
||
|
|
|
||
|
|
RuleFor(x => x.Descripcion)
|
||
|
|
.MaximumLength(DescripcionMaxLength)
|
||
|
|
.WithMessage($"La descripción no puede superar los {DescripcionMaxLength} caracteres.")
|
||
|
|
.When(x => x.Descripcion is not null);
|
||
|
|
}
|
||
|
|
}
|