Added models for presentation layer with data annotations
This commit is contained in:
		| @@ -0,0 +1,27 @@ | ||||
| using System.ComponentModel.DataAnnotations; | ||||
| using Domains; | ||||
|  | ||||
| namespace ApplicationLayer.Services.Applicants.Models; | ||||
|  | ||||
| public class AddressModel | ||||
| { | ||||
|     /// Country part of address | ||||
|     [Required] | ||||
|     [MaxLength(ConfigurationConstraints.CountryNameLength)] | ||||
|     public string Country { get; set; } = null!; | ||||
|  | ||||
|     /// City part of address | ||||
|     [Required] | ||||
|     [MaxLength(ConfigurationConstraints.CityNameLength)] | ||||
|     public string City { get; set; } = null!; | ||||
|  | ||||
|     /// Street part of address | ||||
|     [Required] | ||||
|     [MaxLength(ConfigurationConstraints.StreetNameLength)] | ||||
|     public string Street { get; set; } = null!; | ||||
|  | ||||
|     /// Building part of address | ||||
|     [Required] | ||||
|     [MaxLength(ConfigurationConstraints.BuildingNumberLength)] | ||||
|     public string Building { get; set; } = null!; | ||||
| } | ||||
| @@ -2,48 +2,49 @@ | ||||
|  | ||||
| namespace ApplicationLayer.Services.Applicants.Models; | ||||
|  | ||||
| /// Model of <see cref="Applicant"/> | ||||
| /// Model of | ||||
| /// <see cref="Applicant" /> | ||||
| public class ApplicantModel | ||||
| { | ||||
|     /// <inheritdoc cref="Applicant.Name"/> | ||||
|     /// <inheritdoc cref="Applicant.Name" /> | ||||
|     public Name Name { get; set; } = null!; | ||||
|  | ||||
|     /// <inheritdoc cref="Applicant.Passport"/> | ||||
|     /// <inheritdoc cref="Applicant.Passport" /> | ||||
|     public Passport Passport { get; set; } = null!; | ||||
|  | ||||
|     /// <inheritdoc cref="Applicant.BirthDate"/> | ||||
|     /// <inheritdoc cref="Applicant.BirthDate" /> | ||||
|     public DateTime BirthDate { get; set; } | ||||
|  | ||||
|     /// <inheritdoc cref="Applicant.CountryOfBirth"/> | ||||
|     /// <inheritdoc cref="Applicant.CountryOfBirth" /> | ||||
|     public string CountryOfBirth { get; set; } = null!; | ||||
|  | ||||
|     /// <inheritdoc cref="Applicant.CityOfBirth"/> | ||||
|     /// <inheritdoc cref="Applicant.CityOfBirth" /> | ||||
|     public string CityOfBirth { get; set; } = null!; | ||||
|  | ||||
|     /// <inheritdoc cref="Applicant.Citizenship"/> | ||||
|     /// <inheritdoc cref="Applicant.Citizenship" /> | ||||
|     public string Citizenship { get; set; } = null!; | ||||
|  | ||||
|     /// <inheritdoc cref="Applicant.CitizenshipByBirth"/> | ||||
|     /// <inheritdoc cref="Applicant.CitizenshipByBirth" /> | ||||
|     public string CitizenshipByBirth { get; set; } = null!; | ||||
|  | ||||
|     /// <inheritdoc cref="Applicant.Gender"/> | ||||
|     /// <inheritdoc cref="Applicant.Gender" /> | ||||
|     public Gender Gender { get; set; } | ||||
|  | ||||
|     /// <inheritdoc cref="Applicant.MaritalStatus"/> | ||||
|     /// <inheritdoc cref="Applicant.MaritalStatus" /> | ||||
|     public MaritalStatus MaritalStatus { get; set; } | ||||
|  | ||||
|     /// <inheritdoc cref="Applicant.FatherName"/> | ||||
|     /// <inheritdoc cref="Applicant.FatherName" /> | ||||
|     public Name FatherName { get; set; } = null!; | ||||
|  | ||||
|     /// <inheritdoc cref="Applicant.MotherName"/> | ||||
|     /// <inheritdoc cref="Applicant.MotherName" /> | ||||
|     public Name MotherName { get; set; } = null!; | ||||
|  | ||||
|     /// <inheritdoc cref="Applicant.JobTitle"/> | ||||
|     /// <inheritdoc cref="Applicant.JobTitle" /> | ||||
|     public string JobTitle { get; set; } = null!; | ||||
|  | ||||
|     /// <inheritdoc cref="Applicant.PlaceOfWork"/> | ||||
|     /// <inheritdoc cref="Applicant.PlaceOfWork" /> | ||||
|     public PlaceOfWork PlaceOfWork { get; set; } = null!; | ||||
|  | ||||
|     /// <inheritdoc cref="Applicant.IsNonResident"/> | ||||
|     /// <inheritdoc cref="Applicant.IsNonResident" /> | ||||
|     public bool IsNonResident { get; set; } | ||||
| } | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,19 @@ | ||||
| using System.ComponentModel.DataAnnotations; | ||||
| using Domains; | ||||
|  | ||||
| namespace ApplicationLayer.Services.Applicants.Models; | ||||
|  | ||||
| /// Model of name for presentation layer | ||||
| public class NameModel | ||||
| { | ||||
|     [Required] | ||||
|     [MaxLength(ConfigurationConstraints.NameLength)] | ||||
|     public string FirstName { get; set; } = null!; | ||||
|  | ||||
|     [Required] | ||||
|     [MaxLength(ConfigurationConstraints.NameLength)] | ||||
|     public string Surname { get; set; } = null!; | ||||
|  | ||||
|     [MaxLength(ConfigurationConstraints.NameLength)] | ||||
|     public string? Patronymic { get; set; } | ||||
| } | ||||
| @@ -0,0 +1,26 @@ | ||||
| using System.ComponentModel.DataAnnotations; | ||||
| using Domains; | ||||
|  | ||||
| namespace ApplicationLayer.Services.Applicants.Models; | ||||
|  | ||||
| /// Model of passport fpr presentation layer | ||||
| public class PassportModel | ||||
| { | ||||
|     /// Number of passport | ||||
|     [Required] | ||||
|     [MaxLength(ConfigurationConstraints.PassportNumberLength)] | ||||
|     public string Number { get; set; } = null!; | ||||
|  | ||||
|     /// Issuing authority of passport | ||||
|     [Required] | ||||
|     [MaxLength(ConfigurationConstraints.IssuerNameLength)] | ||||
|     public string Issuer { get; set; } = null!; | ||||
|  | ||||
|     /// Date of issue | ||||
|     [Required] | ||||
|     public DateTime IssueDate { get; set; } | ||||
|  | ||||
|     /// Date when the passport expires | ||||
|     [Required] | ||||
|     public DateTime ExpirationDate { get; set; } | ||||
| } | ||||
| @@ -1,15 +1,22 @@ | ||||
| using Domains.ApplicantDomain; | ||||
| using System.ComponentModel.DataAnnotations; | ||||
| using Domains; | ||||
|  | ||||
| namespace ApplicationLayer.Services.Applicants.Models; | ||||
|  | ||||
| public class PlaceOfWorkModel | ||||
| { | ||||
|     /// Name of hirer | ||||
|     [Required] | ||||
|     [MaxLength(ConfigurationConstraints.PlaceOfWorkNameLength)] | ||||
|     public string Name { get; set; } = null!; | ||||
|  | ||||
|     /// Address of hirer | ||||
|     public Address Address { get; set; } = null!; | ||||
|     [Required] | ||||
|     public AddressModel Address { get; set; } = null!; | ||||
|  | ||||
|     /// Phone number of hirer | ||||
|     [Required] | ||||
|     [MaxLength(ConfigurationConstraints.PhoneNumberLength)] | ||||
|     [MinLength(ConfigurationConstraints.PhoneNumberMinLength)] | ||||
|     public string PhoneNum { get; set; } = null!; | ||||
| } | ||||
| @@ -0,0 +1,26 @@ | ||||
| using Domains; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace ApplicationLayer.Services.Applicants.Models.Validation; | ||||
|  | ||||
| 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 ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using Domains; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace ApplicationLayer.Services.Applicants.Models.Validation; | ||||
|  | ||||
| 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 Domains; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace ApplicationLayer.Services.Applicants.Models.Validation; | ||||
|  | ||||
| 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}"); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user