CustomerValidator.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233
  1. using Quadarax.Application.QLiberace.Base.Repositories;
  2. using Quadarax.Foundation.Core.Value;
  3. namespace Quadarax.Application.QLiberace.Customer.Dtos.Validators
  4. {
  5. public class CustomerValidator : Validator<CustomerWDto>
  6. {
  7. protected override void OnValidate(CustomerWDto validatingObject, ValidatorContext context)
  8. {
  9. CheckIfEmpty("Name", validatingObject.Name, ValidationResult.ValidationSeverityEnum.Error);
  10. CheckIfStringMaxLengthOverflow("Name", validatingObject.Name, 100,
  11. ValidationResult.ValidationSeverityEnum.Error);
  12. CheckIfEmpty("TaxCountryCode", validatingObject.TaxCountryCode, ValidationResult.ValidationSeverityEnum.Error);
  13. CheckIfStringMaxLengthOverflow("TaxCountryCode", validatingObject.TaxCountryCode, 5,
  14. ValidationResult.ValidationSeverityEnum.Error);
  15. if (!string.IsNullOrEmpty(validatingObject.TaxCountryCode))
  16. {
  17. var rcurr = context.GetValue<RepoCountry>("RepoCountry");
  18. CheckIfNull("TaxCountryCode",rcurr.GetByCode(validatingObject.TaxCountryCode), ValidationResult.ValidationSeverityEnum.Error, $"Customer TaxCountryCode not match country code '{validatingObject.TaxCountryCode}' with enumeration");
  19. }
  20. CheckIfStringMaxLengthOverflow("TaxNumber", validatingObject.TaxNumber, 20,
  21. ValidationResult.ValidationSeverityEnum.Error);
  22. CheckIfStringMaxLengthOverflow("VatNumber", validatingObject.VatNumber, 20,
  23. ValidationResult.ValidationSeverityEnum.Error);
  24. }
  25. }
  26. }