SHA256
Compare commits
2
Commits
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
e30fb16bcf | ||
|
|
29e51c016a |
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>
|
||||
|
||||
@@ -30,12 +30,12 @@ public class GuestDocumentEntityService(
|
||||
//Dto must be valid, so null warings shouldn't matter.
|
||||
GuestAddress addressItem = new()
|
||||
{
|
||||
Address = dto.Address,
|
||||
AddressCity = dto.AddressCity,
|
||||
AddressProvince = dto.AddressProvince,
|
||||
AddressState = dto.AddressState,
|
||||
Address = GetValueOrNull(dto.Address),
|
||||
AddressCity = GetValueOrNull(dto.AddressCity),
|
||||
AddressProvince = GetValueOrNull(dto.AddressProvince),
|
||||
AddressState = GetValueOrNull(dto.AddressState),
|
||||
AddressCountry = dto.AddressCountry!,
|
||||
ZipCode = dto.ZipCode,
|
||||
ZipCode = GetValueOrNull(dto.ZipCode),
|
||||
};
|
||||
|
||||
DateTime createTime = DateTime.UtcNow;
|
||||
@@ -45,15 +45,15 @@ public class GuestDocumentEntityService(
|
||||
DocumentType = dto.DocumentType!,
|
||||
DocumentNum = dto.DocumentNum!,
|
||||
IssueDate = dto.IssueDate != null ? DateOnly.FromDateTime(dto.IssueDate!.Value) : null,
|
||||
SupportNum = dto.SupportNum,
|
||||
SupportNum = GetValueOrNull(dto.SupportNum),
|
||||
Nationality = dto.Nationality!,
|
||||
Name = dto.Name!,
|
||||
Surname = dto.Surname!,
|
||||
Surname2 = dto.Surname2,
|
||||
Surname2 = GetValueOrNull(dto.Surname2),
|
||||
BirthDate = DateOnly.FromDateTime(dto.BirthDate!.Value),
|
||||
Gender = dto.Gender,
|
||||
PhoneNumber = dto.PhoneNumber,
|
||||
EmailAddress = dto.EmailAddress,
|
||||
Gender = GetValueOrNull(dto.Gender),
|
||||
PhoneNumber = GetValueOrNull(dto.PhoneNumber),
|
||||
EmailAddress = GetValueOrNull(dto.EmailAddress),
|
||||
AddressDetails = addressItem,
|
||||
CreateTime = createTime,
|
||||
UpdateTime = createTime,
|
||||
@@ -100,12 +100,12 @@ public class GuestDocumentEntityService(
|
||||
//Dto must be valid, so null warings shouldn't matter.
|
||||
GuestAddress addressItem = new()
|
||||
{
|
||||
Address = dto.Address,
|
||||
AddressCity = dto.AddressCity,
|
||||
AddressProvince = dto.AddressProvince,
|
||||
AddressState = dto.AddressState,
|
||||
Address = GetValueOrNull(dto.Address),
|
||||
AddressCity = GetValueOrNull(dto.AddressCity),
|
||||
AddressProvince = GetValueOrNull(dto.AddressProvince),
|
||||
AddressState = GetValueOrNull(dto.AddressState),
|
||||
AddressCountry = dto.AddressCountry!,
|
||||
ZipCode = dto.ZipCode,
|
||||
ZipCode = GetValueOrNull(dto.ZipCode),
|
||||
};
|
||||
|
||||
DateTime updateTime = DateTime.UtcNow;
|
||||
@@ -116,15 +116,15 @@ public class GuestDocumentEntityService(
|
||||
DocumentType = dbItem.DocumentType,
|
||||
DocumentNum = dbItem.DocumentNum,
|
||||
IssueDate = dto.IssueDate != null ? DateOnly.FromDateTime(dto.IssueDate!.Value) : null,
|
||||
SupportNum = dto.SupportNum,
|
||||
SupportNum = GetValueOrNull(dto.SupportNum),
|
||||
Nationality = dto.Nationality!,
|
||||
Name = dto.Name!,
|
||||
Surname = dto.Surname!,
|
||||
Surname2 = dto.Surname2,
|
||||
Surname2 = GetValueOrNull(dto.Surname2),
|
||||
BirthDate = DateOnly.FromDateTime(dto.BirthDate!.Value),
|
||||
Gender = dto.Gender,
|
||||
PhoneNumber = dto.PhoneNumber,
|
||||
EmailAddress = dto.EmailAddress,
|
||||
Gender = GetValueOrNull(dto.Gender),
|
||||
PhoneNumber = GetValueOrNull(dto.PhoneNumber),
|
||||
EmailAddress = GetValueOrNull(dto.EmailAddress),
|
||||
AddressDetails = addressItem,
|
||||
CreateTime = dbItem.CreateTime,
|
||||
UpdateTime = updateTime,
|
||||
@@ -297,5 +297,10 @@ public class GuestDocumentEntityService(
|
||||
return EntityMapping.MapGuestDocumentEntityToDTO(dbItem);
|
||||
}
|
||||
|
||||
private static string? GetValueOrNull(string? dtoValue)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(dtoValue) ? null : dtoValue;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -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