102 lines
3.7 KiB
C#
102 lines
3.7 KiB
C#
using cuqmbr.TravelGuide.Application.Common.FluentValidation;
|
|
using cuqmbr.TravelGuide.Application.Common.Interfaces.Services;
|
|
using cuqmbr.TravelGuide.Domain.Enums;
|
|
using FluentValidation;
|
|
using Microsoft.Extensions.Localization;
|
|
|
|
namespace cuqmbr.TravelGuide.Application.Payments.LiqPay
|
|
.TicketGroups.Commands.GetPaymentLink;
|
|
|
|
public class GetPaymentLinkCommandValidator :
|
|
AbstractValidator<GetPaymentLinkCommand>
|
|
{
|
|
public GetPaymentLinkCommandValidator(
|
|
IStringLocalizer localizer,
|
|
SessionCultureService cultureService)
|
|
{
|
|
RuleFor(tg => tg.PassangerFirstName)
|
|
.NotEmpty()
|
|
.WithMessage(localizer["FluentValidation.NotEmpty"])
|
|
.MaximumLength(32)
|
|
.WithMessage(
|
|
String.Format(
|
|
cultureService.Culture,
|
|
localizer["FluentValidation.MaximumLength"],
|
|
32));
|
|
|
|
RuleFor(tg => tg.PassangerLastName)
|
|
.NotEmpty()
|
|
.WithMessage(localizer["FluentValidation.NotEmpty"])
|
|
.MaximumLength(32)
|
|
.WithMessage(
|
|
String.Format(
|
|
cultureService.Culture,
|
|
localizer["FluentValidation.MaximumLength"],
|
|
32));
|
|
|
|
RuleFor(tg => tg.PassangerPatronymic)
|
|
.NotEmpty()
|
|
.WithMessage(localizer["FluentValidation.NotEmpty"])
|
|
.MaximumLength(32)
|
|
.WithMessage(
|
|
String.Format(
|
|
cultureService.Culture,
|
|
localizer["FluentValidation.MaximumLength"],
|
|
32));
|
|
|
|
RuleFor(tg => tg.PassangerSex)
|
|
.Must((tg, s) => Sex.Enumerations.ContainsValue(s))
|
|
.WithMessage(
|
|
String.Format(
|
|
localizer["FluentValidation.MustBeInEnum"],
|
|
String.Join(
|
|
", ",
|
|
Sex.Enumerations.Values.Select(e => e.Name))));
|
|
|
|
RuleFor(tg => tg.PassangerBirthDate)
|
|
.GreaterThanOrEqualTo(DateOnly.FromDateTime(DateTime.UtcNow.AddYears(-100)))
|
|
.WithMessage(
|
|
String.Format(
|
|
cultureService.Culture,
|
|
localizer["FluentValidation.GreaterThanOrEqualTo"],
|
|
DateOnly.FromDateTime(DateTime.UtcNow.AddYears(-100))));
|
|
|
|
RuleFor(tg => tg.Tickets)
|
|
.IsUnique(t => t.VehicleEnrollmentGuid)
|
|
.WithMessage(localizer["FluentValidation.IsUnique"]);
|
|
|
|
RuleFor(tg => tg.Tickets)
|
|
.IsUnique(t => t.Order)
|
|
.WithMessage(localizer["FluentValidation.IsUnique"]);
|
|
|
|
RuleForEach(tg => tg.Tickets).ChildRules(t =>
|
|
{
|
|
t.RuleFor(t => t.DepartureRouteAddressGuid)
|
|
.NotEmpty()
|
|
.WithMessage(localizer["FluentValidation.NotEmpty"]);
|
|
|
|
t.RuleFor(t => t.ArrivalRouteAddressGuid)
|
|
.NotEmpty()
|
|
.WithMessage(localizer["FluentValidation.NotEmpty"]);
|
|
|
|
t.RuleFor(t => t.Order)
|
|
.GreaterThanOrEqualTo(short.MinValue)
|
|
.WithMessage(
|
|
String.Format(
|
|
cultureService.Culture,
|
|
localizer["FluentValidation.GreaterThanOrEqualTo"],
|
|
short.MinValue))
|
|
.LessThanOrEqualTo(short.MaxValue)
|
|
.WithMessage(
|
|
String.Format(
|
|
cultureService.Culture,
|
|
localizer["FluentValidation.LessThanOrEqualTo"],
|
|
short.MaxValue));
|
|
|
|
t.RuleFor(t => t.VehicleEnrollmentGuid)
|
|
.NotEmpty()
|
|
.WithMessage(localizer["FluentValidation.NotEmpty"]);
|
|
});
|
|
}
|
|
}
|