Started CreateApplication.razor
This commit is contained in:
		| @@ -0,0 +1,21 @@ | ||||
| using System.ComponentModel.DataAnnotations; | ||||
| using VisaApiClient; | ||||
|  | ||||
| namespace BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models | ||||
| { | ||||
|     /// Model of place of work with attributes required for validation to work | ||||
|     public class PlaceOfWorkModel | ||||
|     { | ||||
|         [Required] | ||||
|         [StringLength(ConfigurationConstraints.PlaceOfWorkNameLength, MinimumLength = 1)] | ||||
|         public string Name { get; set; } = default!; | ||||
|  | ||||
|         [Required] | ||||
|         [ValidateComplexType] | ||||
|         public AddressModel Address { get; set; } = new AddressModel(); | ||||
|  | ||||
|         [Required] | ||||
|         [StringLength(ConfigurationConstraints.PhoneNumberLength, MinimumLength = ConfigurationConstraints.PhoneNumberMinLength)] | ||||
|         public string PhoneNum { get; set; } = default!; | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,68 @@ | ||||
| using System.ComponentModel.DataAnnotations; | ||||
| using Newtonsoft.Json; | ||||
| using Newtonsoft.Json.Converters; | ||||
| using VisaApiClient; | ||||
|  | ||||
| namespace BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models | ||||
| { | ||||
|     /// Model of request with attributes required for validation to work | ||||
|     public class RegisterApplicantRequestModel | ||||
|     { | ||||
|         [Required] | ||||
|         [ValidateComplexType] | ||||
|         public RegisterRequestModel RegisterRequest { get; set; } = new(); | ||||
|  | ||||
|         [Required] | ||||
|         [ValidateComplexType] | ||||
|         public NameModel ApplicantName { get; set; } = new(); | ||||
|  | ||||
|         [Required] | ||||
|         [ValidateComplexType] | ||||
|         public PassportModel Passport { get; set; } = new(); | ||||
|  | ||||
|         [Required(AllowEmptyStrings = true)] | ||||
|         public DateTimeOffset BirthDate { get; set; } | ||||
|  | ||||
|         [Required] | ||||
|         [StringLength(70, MinimumLength = 1)] | ||||
|         public string CityOfBirth { get; set; } = default!; | ||||
|  | ||||
|         [Required] | ||||
|         [StringLength(70, MinimumLength = 1)] | ||||
|         public string CountryOfBirth { get; set; } = default!; | ||||
|  | ||||
|         [Required] | ||||
|         [StringLength(30, MinimumLength = 1)] | ||||
|         public string Citizenship { get; set; } = default!; | ||||
|  | ||||
|         [Required] | ||||
|         [StringLength(30, MinimumLength = 1)] | ||||
|         public string CitizenshipByBirth { get; set; } = default!; | ||||
|  | ||||
|         [Required(AllowEmptyStrings = true)] | ||||
|         [JsonConverter(typeof(StringEnumConverter))] | ||||
|         public Gender Gender { get; set; } | ||||
|  | ||||
|         [Required(AllowEmptyStrings = true)] | ||||
|         [JsonConverter(typeof(StringEnumConverter))] | ||||
|         public MaritalStatus MaritalStatus { get; set; } | ||||
|  | ||||
|         [Required] | ||||
|         [ValidateComplexType] | ||||
|         public NameModel FatherName { get; set; } = new(); | ||||
|  | ||||
|         [Required] | ||||
|         [ValidateComplexType] | ||||
|         public NameModel MotherName { get; set; } = new(); | ||||
|  | ||||
|         [Required] | ||||
|         [StringLength(50, MinimumLength = 1)] | ||||
|         public string JobTitle { get; set; } = default!; | ||||
|  | ||||
|         [Required] | ||||
|         [ValidateComplexType] | ||||
|         public PlaceOfWorkModel PlaceOfWork { get; set; } = new(); | ||||
|  | ||||
|         public bool IsNonResident { get; set; } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,13 @@ | ||||
| using System.ComponentModel.DataAnnotations; | ||||
| using VisaApiClient; | ||||
|  | ||||
| namespace BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models | ||||
| { | ||||
|     /// Model of request with attributes required for validation to work | ||||
|     public class RegisterRequestModel | ||||
|     { | ||||
|         [Required] | ||||
|         [ValidateComplexType] | ||||
|         public AuthData AuthData { get; set; } = new AuthData(); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,26 @@ | ||||
| using FluentValidation; | ||||
| using VisaApiClient; | ||||
|  | ||||
| namespace BlazorWebAssemblyVisaApiClient.Validation.Applicants.Validators; | ||||
|  | ||||
| public class NameModelValidator : AbstractValidator<NameModel> | ||||
| { | ||||
|     public NameModelValidator() | ||||
|     { | ||||
|         RuleFor(m => m.FirstName) | ||||
|             .NotEmpty() | ||||
|             .WithMessage("First Name can not be empty") | ||||
|             .MaximumLength(ConfigurationConstraints.NameLength) | ||||
|             .WithMessage($"First Name length must be less than {ConfigurationConstraints.NameLength}"); | ||||
|  | ||||
|         RuleFor(m => m.Surname) | ||||
|             .NotEmpty() | ||||
|             .WithMessage("Surname can not be empty") | ||||
|             .MaximumLength(ConfigurationConstraints.NameLength) | ||||
|             .WithMessage($"Surname length must be less than {ConfigurationConstraints.NameLength}"); | ||||
|  | ||||
|         RuleFor(m => m.Patronymic) | ||||
|             .MaximumLength(ConfigurationConstraints.NameLength) | ||||
|             .WithMessage($"Patronymic length must be less than {ConfigurationConstraints.NameLength}"); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,35 @@ | ||||
| using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider; | ||||
| using FluentValidation; | ||||
| using VisaApiClient; | ||||
|  | ||||
| namespace BlazorWebAssemblyVisaApiClient.Validation.Applicants.Validators; | ||||
|  | ||||
| public class PassportModelValidator : AbstractValidator<PassportModel> | ||||
| { | ||||
|     public PassportModelValidator(IDateTimeProvider dateTimeProvider) | ||||
|     { | ||||
|         RuleFor(r => r.Issuer) | ||||
|             .NotEmpty() | ||||
|             .WithMessage("Passport issuer can not be empty") | ||||
|             .MaximumLength(ConfigurationConstraints.IssuerNameLength) | ||||
|             .WithMessage($"Passport issuer length must be less than {ConfigurationConstraints.IssuerNameLength}"); | ||||
|  | ||||
|         RuleFor(r => r.Number) | ||||
|             .NotEmpty() | ||||
|             .WithMessage("Passport number can not be empty") | ||||
|             .MaximumLength(ConfigurationConstraints.PassportNumberLength) | ||||
|             .WithMessage($"Passport number length must be less than {ConfigurationConstraints.PassportNumberLength}"); | ||||
|  | ||||
|         RuleFor(r => r.ExpirationDate) | ||||
|             .NotEmpty() | ||||
|             .WithMessage("Passport expiration date can not be empty") | ||||
|             .GreaterThan(dateTimeProvider.Now()) | ||||
|             .WithMessage("Can not approve visa for applicants with expired passport"); | ||||
|  | ||||
|         RuleFor(r => r.IssueDate) | ||||
|             .NotEmpty() | ||||
|             .WithMessage("Passport issue date can not be empty") | ||||
|             .LessThanOrEqualTo(dateTimeProvider.Now()) | ||||
|             .WithMessage("Passport issue date must be in past"); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,50 @@ | ||||
| using BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace BlazorWebAssemblyVisaApiClient.Validation.Applicants.Validators; | ||||
|  | ||||
| public class PlaceOfWorkModelValidator : AbstractValidator<PlaceOfWorkModel> | ||||
| { | ||||
|     public PlaceOfWorkModelValidator() | ||||
|     { | ||||
|         RuleFor(p => p.Name) | ||||
|             .NotEmpty() | ||||
|             .WithMessage("Place of work name can not be empty") | ||||
|             .MaximumLength(ConfigurationConstraints.PlaceOfWorkNameLength) | ||||
|             .WithMessage($"Place of work name length must be less than {ConfigurationConstraints.PlaceOfWorkNameLength}"); | ||||
|  | ||||
|         RuleFor(p => p.PhoneNum) | ||||
|             .NotEmpty() | ||||
|             .WithMessage("Place of work phone number can not be empty") | ||||
|             .MaximumLength(ConfigurationConstraints.PhoneNumberLength) | ||||
|             .WithMessage( | ||||
|                 $"Phone number length must be in range from {ConfigurationConstraints.PhoneNumberMinLength} to {ConfigurationConstraints.PhoneNumberLength}") | ||||
|             .MinimumLength(ConfigurationConstraints.PhoneNumberMinLength) | ||||
|             .WithMessage( | ||||
|                 $"Phone number length must be in range from {ConfigurationConstraints.PhoneNumberMinLength} to {ConfigurationConstraints.PhoneNumberLength}"); | ||||
|  | ||||
|         RuleFor(p => p.Address.Country) | ||||
|             .NotEmpty() | ||||
|             .WithMessage("Country name of place of work can not be empty") | ||||
|             .MaximumLength(ConfigurationConstraints.CountryNameLength) | ||||
|             .WithMessage($"Country name of place of work length must be less than {ConfigurationConstraints.CountryNameLength}"); | ||||
|  | ||||
|         RuleFor(p => p.Address.City) | ||||
|             .NotEmpty() | ||||
|             .WithMessage("City name of place of work can not be empty") | ||||
|             .MaximumLength(ConfigurationConstraints.CityNameLength) | ||||
|             .WithMessage($"City name of place of work length must be less than {ConfigurationConstraints.CityNameLength}"); | ||||
|  | ||||
|         RuleFor(p => p.Address.Street) | ||||
|             .NotEmpty() | ||||
|             .WithMessage("Street name of place of work can not be empty") | ||||
|             .MaximumLength(ConfigurationConstraints.StreetNameLength) | ||||
|             .WithMessage($"Street name of place of work length must be less than {ConfigurationConstraints.StreetNameLength}"); | ||||
|  | ||||
|         RuleFor(p => p.Address.Building) | ||||
|             .NotEmpty() | ||||
|             .WithMessage("Building of place of work can not be empty") | ||||
|             .MaximumLength(ConfigurationConstraints.CountryNameLength) | ||||
|             .WithMessage($"Building of place of work length must be less than {ConfigurationConstraints.BuildingNumberLength}"); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,76 @@ | ||||
| using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider; | ||||
| using BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models; | ||||
| using FluentValidation; | ||||
| using VisaApiClient; | ||||
| using PlaceOfWorkModel = BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models.PlaceOfWorkModel; | ||||
|  | ||||
| namespace BlazorWebAssemblyVisaApiClient.Validation.Applicants.Validators; | ||||
|  | ||||
| public class RegisterApplicantRequestValidator : AbstractValidator<RegisterApplicantRequestModel> | ||||
| { | ||||
|     public RegisterApplicantRequestValidator( | ||||
|         IDateTimeProvider dateTimeProvider, | ||||
|         IValidator<NameModel> nameValidator, | ||||
|         IValidator<RegisterRequestModel> registerRequestModelValidator, | ||||
|         IValidator<PassportModel> passportValidator, | ||||
|         IValidator<PlaceOfWorkModel> placeOfWorkModelValidator) | ||||
|     { | ||||
|         RuleFor(r => r.RegisterRequest) | ||||
|             .SetValidator(registerRequestModelValidator); | ||||
|  | ||||
|         RuleFor(r => r.ApplicantName) | ||||
|             .SetValidator(nameValidator); | ||||
|  | ||||
|         RuleFor(r => r.FatherName) | ||||
|             .SetValidator(nameValidator); | ||||
|  | ||||
|         RuleFor(r => r.MotherName) | ||||
|             .SetValidator(nameValidator); | ||||
|  | ||||
|         RuleFor(r => r.Passport) | ||||
|             .SetValidator(passportValidator); | ||||
|  | ||||
|         RuleFor(r => r.BirthDate) | ||||
|             .NotEmpty() | ||||
|             .WithMessage("Birth date can not be empty") | ||||
|             .LessThanOrEqualTo(dateTimeProvider.Now().AddYears(-ConfigurationConstraints.ApplicantMinAge)) | ||||
|             .WithMessage($"Applicant must be older than {ConfigurationConstraints.ApplicantMinAge}"); | ||||
|  | ||||
|         RuleFor(r => r.CountryOfBirth) | ||||
|             .NotEmpty() | ||||
|             .WithMessage("Country of birth can not be empty") | ||||
|             .MaximumLength(ConfigurationConstraints.CountryNameLength) | ||||
|             .WithMessage($"Country of birth name length must be less than {ConfigurationConstraints.CountryNameLength}"); | ||||
|  | ||||
|         RuleFor(r => r.CityOfBirth) | ||||
|             .NotEmpty() | ||||
|             .WithMessage("City of birth can not be empty") | ||||
|             .MaximumLength(ConfigurationConstraints.CityNameLength) | ||||
|             .WithMessage($"City of birth name length must be less than {ConfigurationConstraints.CityNameLength}"); | ||||
|  | ||||
|         RuleFor(r => r.Citizenship) | ||||
|             .NotEmpty() | ||||
|             .WithMessage("Citizenship can not be empty") | ||||
|             .MaximumLength(ConfigurationConstraints.CitizenshipLength) | ||||
|             .WithMessage($"Citizenship length must be less than {ConfigurationConstraints.CitizenshipLength}"); | ||||
|  | ||||
|         RuleFor(r => r.CitizenshipByBirth) | ||||
|             .NotEmpty() | ||||
|             .WithMessage("Citizenship by birth can not be empty") | ||||
|             .MaximumLength(ConfigurationConstraints.CitizenshipLength) | ||||
|             .WithMessage($"Citizenship by birth length must be less than {ConfigurationConstraints.CitizenshipLength}"); | ||||
|  | ||||
|         RuleFor(r => r.Gender).IsInEnum(); | ||||
|  | ||||
|         RuleFor(r => r.MaritalStatus).IsInEnum(); | ||||
|  | ||||
|         RuleFor(r => r.JobTitle) | ||||
|             .NotEmpty() | ||||
|             .WithMessage("Title of job can not be empty") | ||||
|             .MaximumLength(ConfigurationConstraints.JobTitleLength) | ||||
|             .WithMessage($"Title of job length must be less than {ConfigurationConstraints.JobTitleLength}"); | ||||
|  | ||||
|         RuleFor(r => r.PlaceOfWork) | ||||
|             .SetValidator(placeOfWorkModelValidator); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,24 @@ | ||||
| using FluentValidation; | ||||
| using VisaApiClient; | ||||
|  | ||||
| namespace BlazorWebAssemblyVisaApiClient.Validation.Common; | ||||
|  | ||||
| public class AuthDataValidator : AbstractValidator<AuthData> | ||||
| { | ||||
|     public AuthDataValidator() | ||||
|     { | ||||
|         RuleFor(d => d.Email) | ||||
|             .NotEmpty() | ||||
|             .WithMessage("Email can not be empty") | ||||
|             .EmailAddress() | ||||
|             .WithMessage("Email must be valid") | ||||
|             .MaximumLength(ConfigurationConstraints.EmailLength) | ||||
|             .WithMessage($"Email length must be less than {ConfigurationConstraints.EmailLength}"); | ||||
|  | ||||
|         RuleFor(d => d.Password) | ||||
|             .NotEmpty() | ||||
|             .WithMessage("Password can not be empty") | ||||
|             .MaximumLength(ConfigurationConstraints.PasswordLength) | ||||
|             .WithMessage($"Password length must be less than {ConfigurationConstraints.PasswordLength}"); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models; | ||||
| using FluentValidation; | ||||
| using VisaApiClient; | ||||
|  | ||||
| namespace BlazorWebAssemblyVisaApiClient.Validation.Common; | ||||
|  | ||||
| public class RegisterRequestModelValidator : AbstractValidator<RegisterRequestModel> | ||||
| { | ||||
|     public RegisterRequestModelValidator(IValidator<AuthData> authDataValidator) | ||||
|     { | ||||
|         RuleFor(r => r.AuthData) | ||||
|             .SetValidator(authDataValidator); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,23 @@ | ||||
| namespace BlazorWebAssemblyVisaApiClient.Validation; | ||||
|  | ||||
| public static class ConfigurationConstraints | ||||
| { | ||||
|     public const int CityNameLength = 70; | ||||
|     public const int CountryNameLength = 70; | ||||
|     public const int CitizenshipLength = 30; | ||||
|     public const int ReentryPermitNumberLength = 25; | ||||
|     public const int IssuerNameLength = 200; | ||||
|     public const int VisaNameLength = 70; | ||||
|     public const int StreetNameLength = 100; | ||||
|     public const int PlaceOfWorkNameLength = 200; | ||||
|     public const int NameLength = 50; | ||||
|     public const int BuildingNumberLength = 10; | ||||
|     public const int PassportNumberLength = 20; | ||||
|     public const int PhoneNumberLength = 13; | ||||
|     public const int PhoneNumberMinLength = 11; | ||||
|     public const int EmailLength = 254; | ||||
|     public const int PasswordLength = 50; | ||||
|     public const int ApplicantMinAge = 14; | ||||
|     public const int JobTitleLength = 50; | ||||
|     public const int MaxValidDays = 90; | ||||
| } | ||||
| @@ -0,0 +1,40 @@ | ||||
| using System.ComponentModel.DataAnnotations; | ||||
| using VisaApiClient; | ||||
|  | ||||
| namespace BlazorWebAssemblyVisaApiClient.Validation.VisaApplications.Models | ||||
| { | ||||
|     /// Model for request for data annotations validation to work | ||||
|     public class VisaApplicationCreateRequestModel | ||||
|     { | ||||
|         [ValidateComplexType] | ||||
|         public ReentryPermitModel? ReentryPermit { get; set; } = new(); | ||||
|  | ||||
|         [Required] | ||||
|         [MaxLength(ConfigurationConstraints.CountryNameLength)] | ||||
|         public string DestinationCountry { get; set; } = default!; | ||||
|  | ||||
|         [Required] | ||||
|         public VisaCategory VisaCategory { get; set; } | ||||
|  | ||||
|         [Required] | ||||
|         public bool IsForGroup { get; set; } | ||||
|  | ||||
|         [Required] | ||||
|         public RequestedNumberOfEntries RequestedNumberOfEntries { get; set; } | ||||
|  | ||||
|         [Required] | ||||
|         [Range(0, ConfigurationConstraints.MaxValidDays)] | ||||
|         public int ValidDaysRequested { get; set; } | ||||
|  | ||||
|         [Required] | ||||
|         [ValidateComplexType] | ||||
|         public PastVisaModel[] PastVisas { get; set; } = default!; | ||||
|  | ||||
|         [ValidateComplexType] | ||||
|         public PermissionToDestCountryModel? PermissionToDestCountry { get; set; } = new(); | ||||
|  | ||||
|         [Required] | ||||
|         [ValidateComplexType] | ||||
|         public PastVisitModel[] PastVisits { get; set; } = default!; | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user