0
|
1 using System;
|
|
2
|
|
3 namespace BLToolkit.Validation
|
|
4 {
|
|
5 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
|
|
6 public class MinDateValueAttribute : MinValueAttribute
|
|
7 {
|
|
8 public MinDateValueAttribute(int year, int month, int day)
|
|
9 : base(new DateTime(year, month, day))
|
|
10 {
|
|
11 }
|
|
12
|
|
13 public MinDateValueAttribute(int year, int month, int day, string errorMessage)
|
|
14 : this(year, month, day)
|
|
15 {
|
|
16 ErrorMessage = errorMessage;
|
|
17 }
|
|
18
|
|
19 public MinDateValueAttribute(int year, int month, int day, bool isExclusive)
|
|
20 : base(new DateTime(year, month, day), isExclusive)
|
|
21 {
|
|
22 }
|
|
23
|
|
24 public MinDateValueAttribute(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 }
|