SHA256
GuestDocument Validation - Added validation for GuestDocumment Address fields.
This commit is contained in:
1 parent
0ab3957efa
commit
29e51c016a
3 files changed
+47
-16
No files matched your search
@@ -139,6 +139,10 @@
|
||||
<data name="dto.GuestDocument.EmailAddress" xml:space="preserve"><value>Correo Electrónico</value></data>
|
||||
<data name="dto.GuestDocument.CreateTime" xml:space="preserve"><value>Fecha Creación</value></data>
|
||||
<data name="dto.GuestDocument.UpdateTime" xml:space="preserve"><value>Fecha Modificación</value></data>
|
||||
<data name="dto.GuestDocument.validation.Address" xml:space="preserve"><value>Se require al menos uno de los siguientes campos: Ciudad, Pronvincia o Región</value></data>
|
||||
<data name="dto.GuestDocument.validation.Contact" xml:space="preserve"><value>Se require al menos un medio de contacto (teléfono o email)</value></data>
|
||||
<data name="dto.GuestDocument.validation.FormatSupportNumDNI" xml:space="preserve"><value>Formato Inválido para DNI. Formato: 'AAA000000'</value></data>
|
||||
<data name="dto.GuestDocument.validation.FormatSupportNumNIE" xml:space="preserve"><value>Formato Inválido para NIE. Formato: 'E00000000'</value></data>
|
||||
|
||||
<data name="dto.StayEntry.Id" xml:space="preserve"><value>Id</value></data>
|
||||
<data name="dto.StayEntry.DateIn" xml:space="preserve"><value>Fecha Entrada</value></data>
|
||||
@@ -195,6 +199,7 @@
|
||||
<data name="general.address.country" xml:space="preserve"><value>País</value></data>
|
||||
<data name="general.address.zipCode" xml:space="preserve"><value>Código Postal</value></data>
|
||||
|
||||
<data name="general.validation.invalidFormat" xml:space="preserve"><value>Formato invalido</value></data>
|
||||
|
||||
<!-- Common codes -->
|
||||
<data name="enum.ResultCode.Ok" xml:space="preserve"><value>OK</value></data>
|
||||
|
||||
@@ -138,6 +138,10 @@
|
||||
<data name="dto.GuestDocument.EmailAddress" xml:space="preserve"><value>Email Address</value></data>
|
||||
<data name="dto.GuestDocument.CreateTime" xml:space="preserve"><value>Creation Time</value></data>
|
||||
<data name="dto.GuestDocument.UpdateTime" xml:space="preserve"><value>Update Time</value></data>
|
||||
<data name="dto.GuestDocument.validation.Address" xml:space="preserve"><value>Is required at least one of the following fields: City, County or State</value></data>
|
||||
<data name="dto.GuestDocument.validation.Contact" xml:space="preserve"><value>At least 1 contact field (phone or email) is required!</value></data>
|
||||
<data name="dto.GuestDocument.validation.FormatSupportNumDNI" xml:space="preserve"><value>Invalid Format for DNI. Expected 'AAA000000'</value></data>
|
||||
<data name="dto.GuestDocument.validation.FormatSupportNumNIE" xml:space="preserve"><value>Invalid Format for NIE. Expected 'E00000000'</value></data>
|
||||
|
||||
<data name="dto.StayEntry.Id" xml:space="preserve"><value>Id</value></data>
|
||||
<data name="dto.StayEntry.DateIn" xml:space="preserve"><value>Date In</value></data>
|
||||
@@ -194,6 +198,7 @@
|
||||
<data name="general.address.country" xml:space="preserve"><value>Country</value></data>
|
||||
<data name="general.address.zipCode" xml:space="preserve"><value>Zip Code</value></data>
|
||||
|
||||
<data name="general.validation.invalidFormat" xml:space="preserve"><value>Invalid Format</value></data>
|
||||
|
||||
<!-- Common codes -->
|
||||
<data name="enum.ResultCode.Ok" xml:space="preserve"><value>OK</value></data>
|
||||
|
||||
@@ -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<GuestDocumentDTO>
|
||||
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<GuestDocumentDTO>
|
||||
.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<GuestDocumentDTO>
|
||||
// .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());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user