Files
MileageTraker/Web/Utility/DenyPreviousMonthDateAttribute.cs
T
2012-11-30 21:35:06 -05:00

23 lines
634 B
C#

using System;
using System.ComponentModel.DataAnnotations;
namespace MileageTraker.Web.Utility
{
public class DenyPreviousMonthDateAttribute : ValidationAttribute
{
public override bool IsValid(object value)
{
var date = DateTime.Parse(value.ToString());
return date.Date >= GetCutoff();
}
private static DateTime GetCutoff()
{
var today = DateTime.Today;
return today.AddMonths(-1).AddDays(-today.Day + 1); // last two months
if (today.Day > 10)
return today.AddDays(-today.Day); // beginning of this month
return today.AddMonths(-1).AddDays(-today.Day); // beginning of previous month
}
}
}