diff --git a/src/Yavsc.Abstract/Attributes/Validation/YaStringLength.cs b/src/Yavsc.Abstract/Attributes/Validation/YaStringLength.cs index 2a80c4e1..5a304b96 100644 --- a/src/Yavsc.Abstract/Attributes/Validation/YaStringLength.cs +++ b/src/Yavsc.Abstract/Attributes/Validation/YaStringLength.cs @@ -4,17 +4,16 @@ namespace Yavsc.Attributes.Validation { public class YaStringLength: YaValidationAttribute { - public long MinLen { get; set; } = -1; + public long MinimumLength { get; set; } = -1; private long maxLen; - public YaStringLength(long maxLen) : base( - ()=> - "BadStringLength") + public YaStringLength(long maxLen) : base( ()=> "BadStringLength") { this.maxLen = maxLen; } - private long excedent=0; - private long manquant=0; + // hugly ... + static long excedent=0; + static long manquant=0; public override bool IsValid(object value) { @@ -24,23 +23,24 @@ namespace Yavsc.Attributes.Validation string stringValue = value as string; if (stringValue==null) return false; - if (MinLen>=0) + if (MinimumLength>=0) { - if (stringValue.Length=0) { if (stringValue.Length>maxLen) { - excedent = stringValue.Length-maxLen; return false; } } return true; } + public override string FormatErrorMessage(string name) + { + var temp = base.FormatErrorMessage(name); + return string.Format(temp, MinimumLength, maxLen); + } } } \ No newline at end of file diff --git a/src/Yavsc.Abstract/Attributes/Validation/YaValidationAttribute.cs b/src/Yavsc.Abstract/Attributes/Validation/YaValidationAttribute.cs index 598c02b5..5e9c8ca4 100644 --- a/src/Yavsc.Abstract/Attributes/Validation/YaValidationAttribute.cs +++ b/src/Yavsc.Abstract/Attributes/Validation/YaValidationAttribute.cs @@ -15,18 +15,32 @@ namespace Yavsc.Attributes.Validation } + /// + /// Get given string from resources + /// specified by ErrorMessageResourceType + /// + /// + /// + public virtual string GetResourceString(string stringName) + { + var prop = this.ErrorMessageResourceType.GetProperty(stringName); + if (prop==null) + { + return " !e! noprop "+stringName+" in "+ErrorMessageResourceType.Name; + } + else { + return (string) prop.GetValue(null, null); + } + } + public override string FormatErrorMessage(string name) { if (ErrorMessageResourceType == null) // failed :/ - return name; + return base.FormatErrorMessage(name); if (ErrorMessageResourceName == null) // re failed :/ - return name; + return base.FormatErrorMessage(name); - var prop = this.ErrorMessageResourceType.GetProperty(ErrorMessageResourceName); - if (prop==null) // re re failed :/ - return "noprop "+ErrorMessageResourceName+" in "+ErrorMessageResourceType.Name; - return (string) prop.GetValue(null, null); - + return GetResourceString(ErrorMessageResourceName); } } } \ No newline at end of file diff --git a/src/Yavsc.Server/Models/IT/Fixing/Bug.cs b/src/Yavsc.Server/Models/IT/Fixing/Bug.cs index 94dd4902..543b1b84 100644 --- a/src/Yavsc.Server/Models/IT/Fixing/Bug.cs +++ b/src/Yavsc.Server/Models/IT/Fixing/Bug.cs @@ -15,10 +15,14 @@ namespace Yavsc.Models.IT.Fixing public long? FeatureId { get; set; } - [StringLength(240, ErrorMessageResourceType=typeof(Yavsc.Models.IT.Fixing.Bug), ErrorMessageResourceName="TitleTooLong")] + [YaStringLength(240, MinimumLength=4 , + ErrorMessageResourceType=typeof(Yavsc.Models.IT.Fixing.Bug), + ErrorMessageResourceName="TitleSizeError")] public string Title { get; set; } - [StringLength(4096)] + [YaStringLength(4096, + ErrorMessageResourceType=typeof(Yavsc.Models.IT.Fixing.Bug), + ErrorMessageResourceName="DescSizeError")] public string Description { get; set; } public BugStatus Status { get; set; } diff --git a/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.Designer.cs b/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.Designer.cs index 22e5d181..e733a2f3 100644 --- a/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.Designer.cs +++ b/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.Designer.cs @@ -1,12 +1,12 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Mono Runtime Version: 4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ namespace Yavsc.Models.IT.Fixing { using System; @@ -43,9 +43,15 @@ namespace Yavsc.Models.IT.Fixing { } } - public static string TitleTooLong { + public static string TitleSizeError { get { - return ResourceManager.GetString("TitleTooLong", resourceCulture); + return ResourceManager.GetString("TitleSizeError", resourceCulture); + } + } + + public static string DescSizeError { + get { + return ResourceManager.GetString("DescSizeError", resourceCulture); } } } diff --git a/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.en.resx b/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.en.resx index e6f65108..3c96d991 100644 --- a/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.en.resx +++ b/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.en.resx @@ -58,5 +58,8 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - The title is too long + + The title is too long ({0}..{1}) + The description field is too long ({0} to {1}) + \ No newline at end of file diff --git a/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.fr.resx b/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.fr.resx deleted file mode 100644 index 3297698d..00000000 --- a/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.fr.resx +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Le titre est trop long - \ No newline at end of file diff --git a/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.resx b/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.resx index e6f65108..5a567b43 100644 --- a/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.resx +++ b/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.resx @@ -58,5 +58,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - The title is too long + Le titre est trop court ou trop long (sa taille va de {0} à {1}) + Le champ description est trop court ou trop long (sa taille va de {0} à {1}) + \ No newline at end of file