refact.
This commit is contained in:
19
Yavsc.Server/Attributes/ActivityBillingAttribute.cs
Normal file
19
Yavsc.Server/Attributes/ActivityBillingAttribute.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace Yavsc.Attributes
|
||||
{
|
||||
public class ActivityBillingAttribute : Attribute
|
||||
{
|
||||
public string BillingCode { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Identifie une entité de facturation
|
||||
/// </summary>
|
||||
/// <param name="billingCode">Code de facturation,
|
||||
/// Il doit avoir une valeur unique par usage.
|
||||
/// </param>
|
||||
public ActivityBillingAttribute(string billingCode) {
|
||||
BillingCode = billingCode;
|
||||
}
|
||||
}
|
||||
}
|
9
Yavsc.Server/Attributes/ActivitySettingsAttribute.cs
Normal file
9
Yavsc.Server/Attributes/ActivitySettingsAttribute.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace Yavsc.Attributes
|
||||
{
|
||||
public class ActivitySettingsAttribute : Attribute
|
||||
{
|
||||
|
||||
}
|
||||
}
|
16
Yavsc.Server/Attributes/Validation/YaRegularExpression.cs
Normal file
16
Yavsc.Server/Attributes/Validation/YaRegularExpression.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System.Resources;
|
||||
|
||||
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 ResourcesHelpers.GlobalLocalizer[this.ErrorMessageResourceName];
|
||||
}
|
||||
}
|
||||
}
|
37
Yavsc.Server/Attributes/Validation/YaRequiredAttribute.cs
Normal file
37
Yavsc.Server/Attributes/Validation/YaRequiredAttribute.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
namespace Yavsc.Attributes.Validation
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
|
||||
public class YaRequiredAttribute : YaValidationAttribute
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a flag indicating whether the attribute should allow empty strings.
|
||||
/// </summary>
|
||||
public bool AllowEmptyStrings { get; set; }
|
||||
public YaRequiredAttribute (string msg) : base()
|
||||
{
|
||||
ErrorMessage = msg;
|
||||
}
|
||||
public YaRequiredAttribute ()
|
||||
{
|
||||
this.ErrorMessage = ResourcesHelpers.GlobalLocalizer["RequiredField"];
|
||||
|
||||
}
|
||||
public override bool IsValid(object value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// only check string length if empty strings are not allowed
|
||||
var stringValue = value as string;
|
||||
if (stringValue != null && !AllowEmptyStrings) {
|
||||
return stringValue.Trim().Length != 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
58
Yavsc.Server/Attributes/Validation/YaStringLength.cs
Normal file
58
Yavsc.Server/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(
|
||||
ResourcesHelpers.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(
|
||||
ResourcesHelpers.GlobalLocalizer["DetailledMaxStringLength"],
|
||||
maxLen,
|
||||
excedent);
|
||||
} else
|
||||
return string.Format(
|
||||
ResourcesHelpers.GlobalLocalizer["DetailledMinMaxStringLength"],
|
||||
MinLen,
|
||||
maxLen,
|
||||
manquant,
|
||||
excedent);
|
||||
}
|
||||
}
|
||||
}
|
22
Yavsc.Server/Attributes/Validation/YaValidationAttribute.cs
Normal file
22
Yavsc.Server/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(()=> ResourcesHelpers.GlobalLocalizer["validationError"])
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public YaValidationAttribute(Func<string> acr): base(acr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override string FormatErrorMessage(string name)
|
||||
{
|
||||
return ResourcesHelpers.GlobalLocalizer[name];
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user