Guest User

Untitled

a guest
Nov 11th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. using FluentValidation;
  2. using FluentValidation.Attributes;
  3.  
  4. namespace BusinessService.Auth.Models
  5. {
  6. [Validator(typeof(AuthModelValidator))]
  7. public sealed class AuthPostModel
  8. {
  9. string _username;
  10. public string Username
  11. {
  12. get { return _username; }
  13. set { _username = value.Trim(); }
  14. }
  15.  
  16. string _password;
  17. public string Password
  18. {
  19. get { return _password; }
  20. set { _password = value.Trim(); }
  21. }
  22. }
  23. class AuthModelValidator : AbstractValidator<AuthPostModel>
  24. {
  25. public AuthModelValidator()
  26. {
  27. RuleFor(x => x.Username).NotEmpty();
  28. RuleFor(x => x.Username).Length(1, 256)
  29. .When(x => !string.IsNullOrEmpty(x.Username));
  30.  
  31. RuleFor(x => x.Password).NotEmpty();
  32. RuleFor(x => x.Password).Length(1, 32)
  33. .When(x => !string.IsNullOrEmpty(x.Password));
  34. }
  35. }
  36. }
Add Comment
Please, Sign In to add comment