GuestDocument Validation - Added validation for GuestDocumment Address fields.

This commit is contained in:
Daniel-Garmig committed 2026-10-04 13:45:11 +02:00
1 parent 0ab3957efa
commit 29e51c016a
3 files changed
+47 -16

No files matched your search

@@ -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());
}