Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using FluentValidation;
- using FluentValidation.Attributes;
- namespace BusinessService.Auth.Models
- {
- [Validator(typeof(AuthModelValidator))]
- public sealed class AuthPostModel
- {
- string _username;
- public string Username
- {
- get { return _username; }
- set { _username = value.Trim(); }
- }
- string _password;
- public string Password
- {
- get { return _password; }
- set { _password = value.Trim(); }
- }
- }
- class AuthModelValidator : AbstractValidator<AuthPostModel>
- {
- public AuthModelValidator()
- {
- RuleFor(x => x.Username).NotEmpty();
- RuleFor(x => x.Username).Length(1, 256)
- .When(x => !string.IsNullOrEmpty(x.Username));
- RuleFor(x => x.Password).NotEmpty();
- RuleFor(x => x.Password).Length(1, 32)
- .When(x => !string.IsNullOrEmpty(x.Password));
- }
- }
- }
Add Comment
Please, Sign In to add comment