Mercurial > pub > bltoolkit
comparison Source/Validation/MaxDateValueAttribute.cs @ 0:f990fcb411a9
Копия текущей версии из github
| author | cin |
|---|---|
| date | Thu, 27 Mar 2014 21:46:09 +0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:f990fcb411a9 |
|---|---|
| 1 using System; | |
| 2 | |
| 3 namespace BLToolkit.Validation | |
| 4 { | |
| 5 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] | |
| 6 public class MaxDateValueAttribute : MaxValueAttribute | |
| 7 { | |
| 8 public MaxDateValueAttribute(int year, int month, int day) | |
| 9 : base(new DateTime(year, month, day)) | |
| 10 { | |
| 11 } | |
| 12 | |
| 13 public MaxDateValueAttribute(int year, int month, int day, string errorMessage) | |
| 14 : this(year, month, day) | |
| 15 { | |
| 16 ErrorMessage = errorMessage; | |
| 17 } | |
| 18 | |
| 19 public MaxDateValueAttribute(int year, int month, int day, bool isExclusive) | |
| 20 : base(new DateTime(year, month, day), isExclusive) | |
| 21 { | |
| 22 } | |
| 23 | |
| 24 public MaxDateValueAttribute(int year, int month, int day, bool isExclusive, string errorMessage) | |
| 25 : this(year, month, day, isExclusive) | |
| 26 { | |
| 27 ErrorMessage = errorMessage; | |
| 28 } | |
| 29 | |
| 30 public override bool IsValid(ValidationContext context) | |
| 31 { | |
| 32 if (context.IsNull(context)) | |
| 33 return true; | |
| 34 | |
| 35 DateTime contextValue = Convert.ToDateTime(context.Value); | |
| 36 DateTime testValue = (DateTime)GetValue(context); | |
| 37 | |
| 38 return testValue > contextValue || !IsExclusive && testValue == contextValue; | |
| 39 } | |
| 40 } | |
| 41 } |
