using System;
using System.ComponentModel.DataAnnotations;
using MileageTraker.Web.Models;

namespace MileageTraker.Web.Attributes
{
	public class DenyPreviousMonthDateAttribute : ValidationAttribute
	{
		public override bool IsValid(object value)
		{
			DateTime date;
			if (value == null || !DateTime.TryParse(value.ToString(), out date))
				return false;
			return date.Date >= GetCutoff();
		}

		private static DateTime GetCutoff()
		{
			return DomainRules.GetLogEntryCutoff();
		}
	}
}