Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: sum collection property value and compare to some other property value

$
0
0

I'm trying to validate that the hours are equal by comparing Projects hours and  TimeEntry hours where dateworked are same date.

publicclass TimeSheet
{public TimeEntry MondayTime { get; set;}public List<Project> Projects {get;set;}
}publicclass TimeEntry
{publicdouble Hours {get;set;}public DateTime DateWorked {get;set;}
}publicclass Project
{publicdouble Hours {get;set;}public DateTime DateWorked {get;set;}publicstring Name {get;set;}
}// validatorpublicclass TimeSheetValidator : AbstractValidator<TimeSheet>
    {public TimeSheetValidator()
        {
            RuleFor(x => x.MondayTimeEntry).Must((timeSheet, timeEntry) => timeSheet.Projects.All(p=>p.DateWorked == timeEntry.DateWorked)); 
// stuck here how to sum project hours and validate that they are equal to timeentry hours?

            
        }


Viewing all articles
Browse latest Browse all 1917

Trending Articles