private ValidationResponse IsValidUkprn(AddOrganisationViaUkprnViewModel vm) { var validationResponse = new ValidationResponse { Errors = new List <ValidationErrorDetail>() }; var fieldValidationErrors = _validator.IsValidUKPRN(vm.UKPRN); if (fieldValidationErrors.Any()) { validationResponse.Errors.AddRange(fieldValidationErrors); } else { if (!string.IsNullOrWhiteSpace(vm.UKPRN)) { fieldValidationErrors = IsDuplicateUkprn(vm.OrganisationId, vm.UKPRN); if (fieldValidationErrors.Any()) { validationResponse.Errors.AddRange(fieldValidationErrors); } } } return(validationResponse); }
public UpdateOrganisationUkprnViewModelValidator(IRoatpOrganisationValidator validator, IUpdateOrganisationUkprnValidator duplicateValidator) { _validator = validator; _duplicateValidator = duplicateValidator; RuleFor(vm => vm).Custom((vm, context) => { var validationErrors = _validator.IsValidUKPRN(vm.Ukprn?.ToString()); if (!validationErrors.Any()) { validationErrors = _duplicateValidator.IsDuplicateUkprn(vm); } 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); }