no comment
This commit is contained in:
parent
176c0411df
commit
0e49b13965
54 changed files with 6158 additions and 213 deletions
14
Yavsc/Attributes/Validation/YaRegularExpression.cs
Normal file
14
Yavsc/Attributes/Validation/YaRegularExpression.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
namespace Yavsc.Attributes.Validation
|
||||
{
|
||||
public class YaRegularExpression : System.ComponentModel.DataAnnotations.RegularExpressionAttribute {
|
||||
public YaRegularExpression(string pattern): base (pattern)
|
||||
{
|
||||
this.ErrorMessage = pattern;
|
||||
}
|
||||
|
||||
public override string FormatErrorMessage(string name)
|
||||
{
|
||||
return Startup.GlobalLocalizer[this.ErrorMessageResourceName];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,20 +2,8 @@ using System;
|
|||
|
||||
namespace Yavsc.Attributes.Validation
|
||||
{
|
||||
public class YaValidationAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
|
||||
{
|
||||
public YaValidationAttribute() : base(()=> Startup.GlobalLocalizer["validationError"])
|
||||
{
|
||||
|
||||
}
|
||||
public override string FormatErrorMessage(string name)
|
||||
{
|
||||
return Startup.GlobalLocalizer[name];
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
|
||||
public class YaRequiredAttribute : YaValidationAttribute
|
||||
public class YaRequiredAttribute : YaValidationAttribute
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -45,16 +33,5 @@ namespace Yavsc.Attributes.Validation
|
|||
return true;
|
||||
}
|
||||
}
|
||||
public class YaRegularExpression : System.ComponentModel.DataAnnotations.RegularExpressionAttribute {
|
||||
public YaRegularExpression(string pattern): base (pattern)
|
||||
{
|
||||
this.ErrorMessage = pattern;
|
||||
}
|
||||
|
||||
|
||||
public override string FormatErrorMessage(string name)
|
||||
{
|
||||
return Startup.GlobalLocalizer[this.ErrorMessageResourceName];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
58
Yavsc/Attributes/Validation/YaStringLength.cs
Normal file
58
Yavsc/Attributes/Validation/YaStringLength.cs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
namespace Yavsc.Attributes.Validation
|
||||
{
|
||||
public class YaStringLength: YaValidationAttribute
|
||||
{
|
||||
public long MinLen { get; set; } = -1;
|
||||
private long maxLen;
|
||||
public YaStringLength(long maxLen) : base(
|
||||
()=>string.Format(
|
||||
Startup.GlobalLocalizer["BadStringLength"],
|
||||
maxLen))
|
||||
{
|
||||
this.maxLen = maxLen;
|
||||
}
|
||||
|
||||
private long excedent;
|
||||
private long manquant;
|
||||
|
||||
public override bool IsValid(object value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
string stringValue = value as string;
|
||||
if (stringValue==null) return false;
|
||||
if (MinLen>=0)
|
||||
{
|
||||
if (stringValue.Length<MinLen)
|
||||
{
|
||||
manquant = MinLen-stringValue.Length;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (maxLen>=0)
|
||||
{
|
||||
if (stringValue.Length>maxLen) {
|
||||
excedent = stringValue.Length-maxLen;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public override string FormatErrorMessage(string name)
|
||||
{
|
||||
if (MinLen<0) {
|
||||
// DetailledMaxStringLength
|
||||
return string.Format(
|
||||
Startup.GlobalLocalizer["DetailledMaxStringLength"],
|
||||
maxLen,
|
||||
excedent);
|
||||
} else
|
||||
return string.Format(
|
||||
Startup.GlobalLocalizer["DetailledMinMaxStringLength"],
|
||||
MinLen,
|
||||
maxLen,
|
||||
manquant,
|
||||
excedent);
|
||||
}
|
||||
}
|
||||
}
|
||||
22
Yavsc/Attributes/Validation/YaValidationAttribute.cs
Normal file
22
Yavsc/Attributes/Validation/YaValidationAttribute.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
|
||||
namespace Yavsc.Attributes.Validation
|
||||
{
|
||||
public class YaValidationAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
|
||||
{
|
||||
public YaValidationAttribute() : base(()=> Startup.GlobalLocalizer["validationError"])
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public YaValidationAttribute(Func<string> acr): base(acr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override string FormatErrorMessage(string name)
|
||||
{
|
||||
return Startup.GlobalLocalizer[name];
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue