32 lines
1.3 KiB
C#
32 lines
1.3 KiB
C#
using ApplicationLayer.InfrastructureServicesInterfaces;
|
|
using Domains;
|
|
using FluentValidation;
|
|
|
|
namespace ApplicationLayer.Services.VisaApplications.Models.Validation;
|
|
|
|
public class PastVisitModelValidator : AbstractValidator<PastVisitModel>
|
|
{
|
|
public PastVisitModelValidator(IDateTimeProvider dateTimeProvider)
|
|
{
|
|
RuleFor(v => v.StartDate)
|
|
.NotEmpty()
|
|
.WithMessage("Start date of past visit can not be empty")
|
|
.LessThan(v => v.EndDate)
|
|
.WithMessage("Start date of past visit must be earlier than end date")
|
|
.LessThan(dateTimeProvider.Now())
|
|
.WithMessage("Start date of past visit must be in past");
|
|
|
|
RuleFor(v => v.EndDate)
|
|
.NotEmpty()
|
|
.WithMessage("End date of past visit can not be empty");
|
|
|
|
RuleFor(v => v.DestinationCountry)
|
|
.NotEmpty()
|
|
.WithMessage("Destination Country of past visit can not be null")
|
|
.Matches(Constants.EnglishPhraseRegex)
|
|
.WithMessage("Destination Country of past visit can contain only english letters, digits and special symbols")
|
|
.MaximumLength(ConfigurationConstraints.CountryNameLength)
|
|
.WithMessage($"Destination Country of past visit length must be less than {ConfigurationConstraints.CountryNameLength}");
|
|
}
|
|
}
|