Hey guys,
on my input form I have an integer field that can be 0 or greater. Im doing something similar to an education system where this field would represent total credits needed. I then have a collection, which would represent classes, each with their own integer field that corresponds to how many credits that class is worth. I need validation to be sure that the number of combined credits for the class collection is greater or equal to the original credit integer (if credits is greater than 0). I am using a when clause:
Is there any way of accomplishing this?
Thanks a bunch
on my input form I have an integer field that can be 0 or greater. Im doing something similar to an education system where this field would represent total credits needed. I then have a collection, which would represent classes, each with their own integer field that corresponds to how many credits that class is worth. I need validation to be sure that the number of combined credits for the class collection is greater or equal to the original credit integer (if credits is greater than 0). I am using a when clause:
When(tracking => tracking.ElectiveCredits > 0, () =>
{
RuleFor(tracking => tracking.ElectiveCourses).Must(course => Test(5, course)).WithMessage("test");
});
private bool Test(int electiveCredits, Core.Collections.EntityCollection<TrackingCourse> electiveCourses)
{
return electiveCourses.Sum(courses => courses.Credits) >= electiveCredits;
}
My issue is Ive hard coded a value of 5 (random number) when really it needs to be the integer value tracking.ElectiveCreditsIs there any way of accomplishing this?
Thanks a bunch