diff --git a/src/Somnia.GuestLog/Resources/LanguageLocale.es.resx b/src/Somnia.GuestLog/Resources/LanguageLocale.es.resx index c5dc1e9..0de9b1b 100644 --- a/src/Somnia.GuestLog/Resources/LanguageLocale.es.resx +++ b/src/Somnia.GuestLog/Resources/LanguageLocale.es.resx @@ -139,6 +139,10 @@ Correo Electrónico Fecha Creación Fecha Modificación + Se require al menos uno de los siguientes campos: Ciudad, Pronvincia o Región + Se require al menos un medio de contacto (teléfono o email) + Formato Inválido para DNI. Formato: 'AAA000000' + Formato Inválido para NIE. Formato: 'E00000000' Id Fecha Entrada @@ -195,6 +199,7 @@ País Código Postal + Formato invalido OK diff --git a/src/Somnia.GuestLog/Resources/LanguageLocale.resx b/src/Somnia.GuestLog/Resources/LanguageLocale.resx index 3be992c..176b863 100644 --- a/src/Somnia.GuestLog/Resources/LanguageLocale.resx +++ b/src/Somnia.GuestLog/Resources/LanguageLocale.resx @@ -138,6 +138,10 @@ Email Address Creation Time Update Time + Is required at least one of the following fields: City, County or State + At least 1 contact field (phone or email) is required! + Invalid Format for DNI. Expected 'AAA000000' + Invalid Format for NIE. Expected 'E00000000' Id Date In @@ -194,6 +198,7 @@ Country Zip Code + Invalid Format OK diff --git a/src/Somnia.GuestLog/Validators/GuestDocumentDTOValidator.cs b/src/Somnia.GuestLog/Validators/GuestDocumentDTOValidator.cs index 4aa634e..c5107b3 100644 --- a/src/Somnia.GuestLog/Validators/GuestDocumentDTOValidator.cs +++ b/src/Somnia.GuestLog/Validators/GuestDocumentDTOValidator.cs @@ -1,5 +1,6 @@ using FluentValidation; using Somnia.GuestLog.Models.DTOs; +using Somnia.GuestLog.Resources; using Somnia.GuestLog.Services; using Somnia.GuestLog.Utils; @@ -30,13 +31,15 @@ public class GuestDocumentDTOValidator : ValueValidator RuleFor(x => x.SupportNum) .Cascade(CascadeMode.Stop) .NotEmpty() - .Matches(RegexUtils.RegexGuestDocSupportNumberDNI()).WithMessage("Invalid Format for DNI. Expected 'AAA000000'.") + .Matches(RegexUtils.RegexGuestDocSupportNumberDNI()) + .WithMessage((_) => LanguageLocale.dto_GuestDocument_validation_FormatSupportNumDNI) .When(x => x.DocumentType == GuestConsts.DocumentType_DNI); RuleFor(x => x.SupportNum) .Cascade(CascadeMode.Stop) .NotEmpty() - .Matches(RegexUtils.RegexGuestDocSupportNumberNIE()).WithMessage("Invalid Format for NIE. Expected 'E00000000'.") + .Matches(RegexUtils.RegexGuestDocSupportNumberNIE()) + .WithMessage((_) => LanguageLocale.dto_GuestDocument_validation_FormatSupportNumNIE) .When(x => x.DocumentType == GuestConsts.DocumentType_NIE); RuleFor(x => x.Name) @@ -63,14 +66,44 @@ public class GuestDocumentDTOValidator : ValueValidator .When(x => !string.IsNullOrEmpty(x.EmailAddress)); RuleFor(x => x.PhoneNumber) - .Matches(RegexUtils.RegexPhoneNumber()).WithMessage("Invalid format") + .Matches(RegexUtils.RegexPhoneNumber()) + .WithMessage((_) => LanguageLocale.general_validation_invalidFormat) .When(x => !string.IsNullOrEmpty(x.PhoneNumber)); // Phone is required if mail is empty. RuleFor(x => x.PhoneNumber) .NotNull() .When(x => string.IsNullOrEmpty(x.EmailAddress)) - .WithMessage("At least 1 contact field (phone or email) is required!"); + .WithMessage((_) => LanguageLocale.dto_GuestDocument_validation_Contact); + + + RuleFor(x => x.Address) + .NotEmpty() + .Length(1, 100); + + //For Spain Address -> City and Province are required. + RuleFor(x => x.AddressCity) + .Cascade(CascadeMode.Stop) + .NotEmpty() + .When(x => x.AddressCountry == GuestConsts.CountryCode_ESP) + .MaximumLength(100); + RuleFor(x => x.AddressProvince) + .NotEmpty() + .When(x => x.AddressCountry == GuestConsts.CountryCode_ESP) + .MaximumLength(100); + + //For other countries -> At least 1 field + RuleFor(x => x.AddressCity) + .Cascade(CascadeMode.Stop) + .NotEmpty() + .When(x => x.AddressCountry != GuestConsts.CountryCode_ESP + && string.IsNullOrEmpty(x.AddressProvince) && string.IsNullOrEmpty(x.AddressState)) + .WithMessage((_) => LanguageLocale.dto_GuestDocument_validation_Address) + .MaximumLength(100); + + RuleFor(x => x.ZipCode) + .NotEmpty() + .Length(1, 20); RuleFor(x => x.AddressCountry) .NotEmpty() @@ -81,18 +114,6 @@ public class GuestDocumentDTOValidator : ValueValidator // .Length(1, 100) // .CreditCard(); - // RuleFor(x => x.Address.Address) - // .NotEmpty() - // .Length(1, 100); - - // RuleFor(x => x.Address.City) - // .NotEmpty() - // .Length(1, 100); - - // RuleFor(x => x.Address.Country) - // .NotEmpty() - // .Length(1, 100); - // RuleForEach(x => x.OrderDetails) // .SetValidator(new OrderDetailsModelFluentValidator()); }