To resolve your issue you can test the following code for the IsDateValid property:
[RuleFromBoolProperty(CustomMessageTemplate = "DateIsValid", UsedProperties = "TransactionDate", SkipNullOrEmptyValues = false)]
public bool IsDateValid
{
get
{
if (!Session.IsNewObject(this))
return true;var dt = DateTime.Today;
/*
//You can set your filter
var criteria = CriteriaOperator.Parse("TransactionDate < ?", dt);
*/
var list = new XPCollection<TestClass>(Session, null,
new SortProperty("TransactionDate", SortingDirection.Ascending));
//var list = new XPCollection<TestClass>(Session, criteria,
// new SortProperty("TransactionDate", SortingDirection.Ascending));var mostrecent = (DateTime)list[list.Count - 1].GetMemberValue("TransactionDate");
var loanNo = list[list.Count - 1].GetMemberValue("LoanNo");
if (TransactionDate >= mostrecent && TransactionDate >= dt) return true;
var message = "Please, enter correct date";
throw new UserFriendlyException(message);
}
}
I hope you find this information helpful.
Feel free to contact us if you have any questions.
Regards,
Sasha.