public UpdateOrganisationLegalNameViewModelValidator(IRoatpOrganisationValidator validator) { _validator = validator; RuleFor(vm => vm).Custom((vm, context) => { var validationErrors = _validator.IsValidLegalName(vm.LegalName); if (!validationErrors.Any()) { return; } foreach (var error in validationErrors) { context.AddFailure(error.Field, error.ErrorMessage); } }); }
public async Task <ValidationResponse> ValidateOrganisationDetails(AddOrganisationViewModel viewModel) { var validationResponse = new ValidationResponse { Errors = new List <ValidationErrorDetail>() }; var fieldValidationErrors = _organisationValidator.IsValidLegalName(viewModel.LegalName); if (fieldValidationErrors.Any()) { validationResponse.Errors.AddRange(fieldValidationErrors); } fieldValidationErrors = _organisationValidator.IsValidUKPRN(viewModel.UKPRN); if (fieldValidationErrors.Any()) { validationResponse.Errors.AddRange(fieldValidationErrors); } else { if (!String.IsNullOrWhiteSpace(viewModel.UKPRN)) { fieldValidationErrors = IsDuplicateUKPRN(viewModel.OrganisationId, viewModel.UKPRN); if (fieldValidationErrors.Any()) { validationResponse.Errors.AddRange(fieldValidationErrors); } } } fieldValidationErrors = _organisationValidator.IsValidCompanyNumber(viewModel.CompanyNumber); if (fieldValidationErrors.Any()) { validationResponse.Errors.AddRange(fieldValidationErrors); } else { if (!String.IsNullOrWhiteSpace(viewModel.CompanyNumber)) { fieldValidationErrors = IsDuplicateCompanyNumber(viewModel.OrganisationId, viewModel.CompanyNumber); if (fieldValidationErrors.Any()) { validationResponse.Errors.AddRange(fieldValidationErrors); } } } fieldValidationErrors = _organisationValidator.IsValidCharityNumber(viewModel.CharityNumber); if (fieldValidationErrors.Any()) { validationResponse.Errors.AddRange(fieldValidationErrors); } else { if (!String.IsNullOrWhiteSpace(viewModel.CharityNumber)) { fieldValidationErrors = IsDuplicateCharityNumber(viewModel.OrganisationId, viewModel.CharityNumber); if (fieldValidationErrors.Any()) { validationResponse.Errors.AddRange(fieldValidationErrors); } } } fieldValidationErrors = _organisationValidator.IsValidTradingName(viewModel.TradingName); if (fieldValidationErrors.Any()) { validationResponse.Errors.AddRange(fieldValidationErrors); } return(validationResponse); }