GuestLog - GuestDocument pages initial implementation

This commit is contained in:
2026-06-21 17:10:27 +02:00
parent 86fadf97b4
commit 76b2695c02
24 changed files with 832 additions and 54 deletions
@@ -0,0 +1,88 @@
using FluentValidation;
using Somnia.GuestLog.Models.DTOs;
namespace Somnia.GuestLog.Validators;
/// <summary>
/// Validator for GuestDocumentDTO which contains multiple rules and can be shared with the back end API
/// </summary>
public class GuestDocumentDTOValidator : AbstractValidator<GuestDocumentDTO>
{
public GuestDocumentDTOValidator()
{
RuleFor(x => x.DocumentType)
.NotEmpty()
.Must(val => val != null && GuestConsts.DocumentTypeList.Contains(val));
RuleFor(x => x.DocumentNum)
.NotEmpty()
.Length(6, 32);
RuleFor(x => x.IssueDate)
.NotEmpty()
.LessThanOrEqualTo(DateTime.Today);
RuleFor(x => x.Name)
.NotEmpty()
.Length(1, 100);
RuleFor(x => x.Surname)
.NotEmpty()
.Length(1, 100);
RuleFor(x => x.BirthDate)
.NotEmpty()
.LessThanOrEqualTo(DateTime.Today);
RuleFor(x => x.Nationality)
.NotEmpty()
.Must(val => val != null && GuestConsts.CountryList.ContainsKey(val));
//Contact Fields
RuleFor(x => x.EmailAddress)
.EmailAddress()
.When(x => !string.IsNullOrEmpty(x.EmailAddress));
RuleFor(x => x.PhoneNumber)
.Matches(GuestConsts.regexPattern_phoneNum)
.When(x => !string.IsNullOrEmpty(x.PhoneNumber));
RuleFor(x => x.AddressCountry)
.NotEmpty()
.Must(val => val != null && GuestConsts.CountryList.ContainsKey(val));
// RuleFor(x => x.Email)
// .Cascade(CascadeMode.Stop)
// .NotEmpty()
// .EmailAddress()
// .MustAsync(async (value, _) => await IsUniqueAsync(value));
// RuleFor(x => x.CCNumber)
// .NotEmpty()
// .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());
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GuestDocumentDTO>.CreateWithOptions((GuestDocumentDTO)model, x =>
x.IncludeProperties(propertyName)));
return result.IsValid ? [] : result.Errors.Select(e => e.ErrorMessage);
};
}