Release 1.0.8-rc10
This commit is contained in:
parent
d5b2930092
commit
8b9a9103fc
9 changed files with 302 additions and 19 deletions
19
src/Yavsc.Abstract/Workflow/Country.cs
Normal file
19
src/Yavsc.Abstract/Workflow/Country.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Yavsc.Models.Workflow
|
||||
{
|
||||
/// <summary>
|
||||
/// Supported country of exercise for performer profile validations.
|
||||
/// </summary>
|
||||
public class Country
|
||||
{
|
||||
[Key]
|
||||
[MaxLength(2)]
|
||||
[MinLength(2)]
|
||||
public string Code { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[MaxLength(64)]
|
||||
public string DisplayName { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ namespace Yavsc.Workflow
|
|||
public interface IPerformerProfile
|
||||
{
|
||||
string PerformerId { get; set; }
|
||||
string ExerciseCountryCode { get; set; }
|
||||
string SIREN { get; set; }
|
||||
bool AcceptNotifications { get; set; }
|
||||
long OrganizationAddressId { get; set; }
|
||||
|
|
|
|||
86
src/Yavsc.Abstract/Workflow/PerformerCodeInputValidation.cs
Normal file
86
src/Yavsc.Abstract/Workflow/PerformerCodeInputValidation.cs
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Yavsc.Models.Workflow
|
||||
{
|
||||
/// <summary>
|
||||
/// Validation rule for performer business code input by country.
|
||||
/// </summary>
|
||||
public class PerformerCodeInputValidation
|
||||
{
|
||||
[Key]
|
||||
public long Id { get; set; }
|
||||
|
||||
[Required]
|
||||
[MaxLength(2)]
|
||||
[MinLength(2)]
|
||||
public string CountryCode { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[MaxLength(256)]
|
||||
public string RegularExpression { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[MaxLength(128)]
|
||||
public string ErrorMessage { get; set; } = string.Empty;
|
||||
|
||||
[ForeignKey(nameof(CountryCode))]
|
||||
public Country Country { get; set; }
|
||||
}
|
||||
|
||||
public static class PerformerCodeInputValidationCatalog
|
||||
{
|
||||
public static readonly IReadOnlyList<Country> Countries = new List<Country>
|
||||
{
|
||||
new() { Code = "fr", DisplayName = "France" },
|
||||
new() { Code = "en", DisplayName = "England" },
|
||||
new() { Code = "pt", DisplayName = "Portugal" },
|
||||
};
|
||||
|
||||
public static readonly IReadOnlyList<PerformerCodeInputValidation> Rules = new List<PerformerCodeInputValidation>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Id = 1,
|
||||
CountryCode = "fr",
|
||||
RegularExpression = "^[0-9]{9,14}$",
|
||||
ErrorMessage = "Le code FR doit contenir entre 9 et 14 chiffres."
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = 2,
|
||||
CountryCode = "en",
|
||||
RegularExpression = "^[A-Za-z0-9]{8,14}$",
|
||||
ErrorMessage = "Le code EN doit contenir entre 8 et 14 caracteres alphanumeriques."
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = 3,
|
||||
CountryCode = "pt",
|
||||
RegularExpression = "^[0-9]{9}$",
|
||||
ErrorMessage = "Le code PT doit contenir exactement 9 chiffres."
|
||||
},
|
||||
};
|
||||
|
||||
public static string NormalizeCountryCode(string? countryCode)
|
||||
{
|
||||
return (countryCode ?? string.Empty).Trim().ToLowerInvariant();
|
||||
}
|
||||
|
||||
public static PerformerCodeInputValidation? GetRule(string? countryCode)
|
||||
{
|
||||
var normalized = NormalizeCountryCode(countryCode);
|
||||
foreach (var rule in Rules)
|
||||
{
|
||||
if (string.Equals(rule.CountryCode, normalized, StringComparison.Ordinal))
|
||||
{
|
||||
return rule;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue