Add nwe DataAnnotation DatetimeNotInThePast
This commit is contained in:
parent
80525fa4be
commit
0d1e880d18
1 changed files with 22 additions and 0 deletions
22
Retroactiune.WebAPI/DataAnnotations/DatetimeNotInThePast.cs
Normal file
22
Retroactiune.WebAPI/DataAnnotations/DatetimeNotInThePast.cs
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
using System;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Retroactiune.DataAnnotations
|
||||||
|
{
|
||||||
|
public class DatetimeNotInThePast : ValidationAttribute
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validates the given DateTime object to be null or greater than the UtcNow date.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">An DateTime object.</param>
|
||||||
|
/// <returns>True if the date is null or in the future, false otherwise.</returns>
|
||||||
|
public override bool IsValid(object value)
|
||||||
|
{
|
||||||
|
// TODO: Test
|
||||||
|
var now = DateTime.UtcNow;
|
||||||
|
var date = value as DateTime?;
|
||||||
|
return !(date <= now);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue