diff options
author | crupest <crupest@outlook.com> | 2021-06-01 23:22:47 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-06-01 23:22:47 +0800 |
commit | 7e709bf5bc514eda87f9ea87b703d1f6cbb3662a (patch) | |
tree | 718ad2cc37a66a65c564dbfcc71b218e93ad33d2 /BackEnd/Timeline/Models/Validation | |
parent | 5ead84a292481b43f44ae3d044193901045ce092 (diff) | |
download | timeline-7e709bf5bc514eda87f9ea87b703d1f6cbb3662a.tar.gz timeline-7e709bf5bc514eda87f9ea87b703d1f6cbb3662a.tar.bz2 timeline-7e709bf5bc514eda87f9ea87b703d1f6cbb3662a.zip |
feat: Add ways to reset timeline or post color.
Diffstat (limited to 'BackEnd/Timeline/Models/Validation')
-rw-r--r-- | BackEnd/Timeline/Models/Validation/ColorValidator.cs | 34 | ||||
-rw-r--r-- | BackEnd/Timeline/Models/Validation/Validator.cs | 2 |
2 files changed, 35 insertions, 1 deletions
diff --git a/BackEnd/Timeline/Models/Validation/ColorValidator.cs b/BackEnd/Timeline/Models/Validation/ColorValidator.cs index c5ad833d..4f7accc5 100644 --- a/BackEnd/Timeline/Models/Validation/ColorValidator.cs +++ b/BackEnd/Timeline/Models/Validation/ColorValidator.cs @@ -4,8 +4,22 @@ namespace Timeline.Models.Validation {
public class ColorValidator : Validator<string>
{
+ public bool PermitEmpty { get; set; } = false;
+ public bool PermitDefault { get; set; } = false;
+ public string DefaultValue { get; set; } = "default";
+
protected override (bool, string) DoValidate(string value)
{
+ if (PermitEmpty && value.Length == 0)
+ {
+ return (true, GetSuccessMessage());
+ }
+
+ if (PermitDefault && value == DefaultValue)
+ {
+ return (true, GetSuccessMessage());
+ }
+
if (!value.StartsWith('#'))
{
return (false, "Color must starts with '#'.");
@@ -32,9 +46,29 @@ namespace Timeline.Models.Validation [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
public class ColorAttribute : ValidateWithAttribute
{
+ private ColorValidator Validator => (ColorValidator)_validator;
+
public ColorAttribute() : base(typeof(ColorValidator))
{
}
+
+ public bool PermitEmpty
+ {
+ get => Validator.PermitEmpty;
+ set => Validator.PermitEmpty = value;
+ }
+
+ public bool PermitDefault
+ {
+ get => Validator.PermitDefault;
+ set => Validator.PermitDefault = value;
+ }
+
+ public string DefaultValue
+ {
+ get => Validator.DefaultValue;
+ set => Validator.DefaultValue = value;
+ }
}
}
diff --git a/BackEnd/Timeline/Models/Validation/Validator.cs b/BackEnd/Timeline/Models/Validation/Validator.cs index d334960e..0e1f7445 100644 --- a/BackEnd/Timeline/Models/Validation/Validator.cs +++ b/BackEnd/Timeline/Models/Validation/Validator.cs @@ -77,7 +77,7 @@ namespace Timeline.Models.Validation AllowMultiple = false)]
public class ValidateWithAttribute : ValidationAttribute
{
- private readonly IValidator _validator;
+ protected readonly IValidator _validator;
/// <summary>
/// Create with a given validator.
|