foolproof.core validation to compare inital date and return date

399 Views Asked by At

I was using GreaterThan on model data notation after installing foolproof.core but when I insert a datetime on returndate which is less than initial date error message doesn't get displayed .Do I have to use service configuration or what is the problem .I couldn't get full documentation on how to use foolproof on asp.net core mvc application.

Model

    [GreaterThan("InitialDate", ErrorMessage = "Insert Return Date greater than Initial Date!!!")]
    [DisplayName("Return Date")]
    [Required(ErrorMessage = "Insert Return Date!!!")]
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
    public DateTime? ReturnDate { get; set; }

    [GreaterThan("requestDate", ErrorMessage = "Insert Initial Date greater than Request Date!!!")]
    [DisplayName("Initial Date")]
    [Required(ErrorMessage = "Insert Initial Date!!!")]
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
    public DateTime? InitialDate { get; set; } 
1

There are 1 best solutions below

0
Marcel On

You have to register FoolProof in the startup.cs ConfigureServices method

public override void ConfigureServices(IServiceCollection services)
{           
    ...

    services.AddFoolProof();
}