/// <summary> /// Constructor method. /// </summary> public ErrorViewModel(HttpStatusCode statusCode, string errorMessage = null) { Code = (int)statusCode; Message = errorMessage; if (!string.IsNullOrWhiteSpace(Message)) { return; } switch (statusCode) { case HttpStatusCode.BadRequest: Message = GlobalizationManager.GetLocalizedString("Errors_BadRequestMessage"); break; case HttpStatusCode.Forbidden: Message = GlobalizationManager.GetLocalizedString("Errors_ForbiddenMessage"); break; case HttpStatusCode.NotFound: Message = GlobalizationManager.GetLocalizedString("Errors_NotFoundMessage"); break; case HttpStatusCode.Unauthorized: Message = GlobalizationManager.GetLocalizedString("Errors_UnauthorizedMessage"); break; default: Message = GlobalizationManager.GetLocalizedString("Errors_GeneralErrorMessage"); break; } }
/// <summary> /// Constructor method. /// </summary> public ProfileEditViewModelValidator(SharedContext context, IIdentityRepository identityRepository) { _context = context; _identityRepository = identityRepository; // Name RuleFor(model => model.FullName).NotEmpty(); RuleFor(model => model.FullName).Length(0, _Constants.UsersFullNameMaxLength).WithMessage(GlobalizationManager.GetLocalizedString("_Validation_MaxLength")); // Email RuleFor(model => model.Email).NotEmpty(); RuleFor(model => model.Email).Matches(_RegularExpressions.SimpleEmailPattern); RuleFor(model => model.Email).Length(0, _Constants.UsersEmailMaxLength).WithMessage(GlobalizationManager.GetLocalizedString("_Validation_MaxLength")); RuleFor(model => model.Email).Must(BeUniqueOrCurrentEmail).WithMessage(GlobalizationManager.GetLocalizedString("_Validation_EmailTakenError")); // Username RuleFor(model => model.UserName).NotEmpty(); RuleFor(model => model.UserName).Matches(_RegularExpressions.UserNamePattern); RuleFor(model => model.UserName).Length(0, _Constants.UsersUserNameMaxLength).WithMessage(GlobalizationManager.GetLocalizedString("_Validation_MaxLength")); RuleFor(model => model.UserName).Must(BeUniqueOrCurrentUsername).WithMessage(GlobalizationManager.GetLocalizedString("_Validation_UserNameTakenError")); // Picture Blob Id RuleFor(model => model.PictureBlobId).Must(BeExistingPictureBlobId).WithMessage(GlobalizationManager.GetLocalizedString("_Validation_BlobIdInvalidError")); // Globalization RuleFor(model => model.CultureId).NotEmpty(); RuleFor(model => model.UICultureId).NotEmpty(); RuleFor(model => model.TimeZoneId).NotEmpty(); }
public AccountSignUpViewModelValidator(IIdentityRepository identityRepository) { _identityRepository = identityRepository; // Name RuleFor(model => model.Name).NotEmpty(); RuleFor(model => model.Name).Length(0, _Constants.UsersFullNameMaxLength).WithMessage(GlobalizationManager.GetLocalizedString("_Validation_MaxLength")); // Email RuleFor(model => model.Email).NotEmpty(); RuleFor(model => model.Email).Matches(_RegularExpressions.SimpleEmailPattern); RuleFor(model => model.Email).Length(0, _Constants.UsersEmailMaxLength).WithMessage(GlobalizationManager.GetLocalizedString("_Validation_MaxLength")); RuleFor(model => model.Email).Must(BeUniqueEmail).WithMessage(GlobalizationManager.GetLocalizedString("_Validation_EmailTakenError")); // Password RuleFor(model => model.Password).NotEmpty(); RuleFor(model => model.Password).Length(_Constants.UsersPasswordMinLength, int.MaxValue).WithMessage(GlobalizationManager.GetLocalizedString("_Validation_MinLength")); // Confirm Password RuleFor(model => model.Password2).NotEmpty(); RuleFor(model => model.Password2).Equal(model => model.Password).WithMessage(GlobalizationManager.GetLocalizedString("_Validation_PasswordsDoNotMatchError")); // Terms Of Use Acceptance RuleFor(model => model.TermsAcceptance).SetValidator(new RequiredCheckboxValidator()).WithMessage(GlobalizationManager.GetLocalizedString("_Validation_TermsAcceptanceError")); }
public UserViewModelValidator(IIdentityRepository identityRepository) { _identityRepository = identityRepository; // Validate name and email only when adding new user. When(model => model.Id <= 0, () => { // Name RuleFor(model => model.FullName).NotEmpty(); RuleFor(model => model.FullName).Length(0, _Constants.UsersFullNameMaxLength).WithMessage(GlobalizationManager.GetLocalizedString("_Validation_MaxLength")); // Email RuleFor(model => model.Email).NotEmpty(); RuleFor(model => model.Email).Matches(_RegularExpressions.SimpleEmailPattern); RuleFor(model => model.Email).Length(0, _Constants.UsersEmailMaxLength).WithMessage(GlobalizationManager.GetLocalizedString("_Validation_MaxLength")); RuleFor(model => model.Email).Must(BeUniqueEmail).WithMessage(GlobalizationManager.GetLocalizedString("_Validation_EmailTakenError")); }); // Realms RuleFor(model => model.Realms).NotEmpty(); // Roles RuleFor(model => model.Roles).NotEmpty(); }
protected string GetLocalizedString(string resourceKey, params object[] formatParams) { return(GlobalizationManager.GetLocalizedString(resourceKey, formatParams)); }
public AccountPasswordRecoverViewModelValidator() { // Email RuleFor(model => model.Email).NotEmpty(); RuleFor(model => model.Email).Matches(_RegularExpressions.SimpleEmailPattern); RuleFor(model => model.Email).Length(0, _Constants.UsersEmailMaxLength).WithMessage(GlobalizationManager.GetLocalizedString <AreaResources>("_Validation_MaxLength")); }
/// <summary> /// Constructor method. /// </summary> public AccountPasswordChangeViewModelValidator() { // Password RuleFor(model => model.Password).NotEmpty(); RuleFor(model => model.Password).Length(_Constants.UsersPasswordMinLength, int.MaxValue).WithMessage(GlobalizationManager.GetLocalizedString <AreaResources>("_Validation_MinLength")); // New Password RuleFor(model => model.NewPassword).NotEmpty(); RuleFor(model => model.NewPassword).Length(_Constants.UsersPasswordMinLength, int.MaxValue).WithMessage(GlobalizationManager.GetLocalizedString <AreaResources>("_Validation_MinLength")); // New Password Confirmation RuleFor(model => model.NewPassword2).NotEmpty(); RuleFor(model => model.NewPassword2).Equal(model => model.NewPassword).WithMessage(GlobalizationManager.GetLocalizedString <AreaResources>("_Validation_PasswordsDoNotMatchError")); }
/// <summary> /// Constructor method. /// </summary> public UploadPictureViewModelValidator() { // Image RuleFor(model => model.Picture).NotNull(); RuleFor(model => model.Picture).Must(BeOfValidContentLength).WithMessage(model => string.Format(GlobalizationManager.GetLocalizedString("_Validation_BlobSizeLimitError"), model?.Picture?.FileName ?? string.Empty) ); RuleFor(model => model.Picture).Must(BeImageMimeType).WithMessage(model => string.Format(GlobalizationManager.GetLocalizedString("_Validation_BlobImageMimeTypeError", model?.Picture?.FileName ?? string.Empty)) ); }
public AccountPasswordRecoverResponseViewModelValidator() { // Email RuleFor(model => model.Email).NotEmpty(); RuleFor(model => model.Email).Matches(_RegularExpressions.SimpleEmailPattern); RuleFor(model => model.Email).Length(0, _Constants.UsersEmailMaxLength).WithMessage(GlobalizationManager.GetLocalizedString("_Validation_MaxLength")); // Password RuleFor(model => model.NewPassword).NotEmpty(); RuleFor(model => model.NewPassword).Length(_Constants.UsersPasswordMinLength, int.MaxValue).WithMessage(GlobalizationManager.GetLocalizedString("_Validation_MinLength")); // Confirm Password RuleFor(model => model.NewPassword2).NotEmpty(); RuleFor(model => model.NewPassword2).Equal(model => model.NewPassword).WithMessage(GlobalizationManager.GetLocalizedString("_Validation_PasswordsDoNotMatchError")); }