Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Finally got it working after I re-read the <a href="http://fluentvalidation.codeplex.com/wikipage?title=Validators" rel="noreferrer">documentation</a>: <em>"Note that there is an additional overload for Must that also accepts an instance of the parent object being validated."</em></p> <pre><code>public class EventModelValidator : AbstractValidator&lt;EventViewModel&gt; { public EventModelValidator() { RuleFor(x =&gt; x.StartDate) .NotEmpty().WithMessage("Date is required!") .Must(BeAValidDate).WithMessage("Invalid date"); RuleFor(x =&gt; x.StartTime) .NotEmpty().WithMessage("Start time is required!") .Must(BeAValidTime).WithMessage("Invalid Start time"); RuleFor(x =&gt; x.EndTime) .NotEmpty().WithMessage("End time is required!") .Must(BeAValidTime).WithMessage("Invalid End time") // new .Must(BeGreaterThan).WithMessage("End time needs to be greater than start time"); RuleFor(x =&gt; x.Title).NotEmpty().WithMessage("A title is required!"); } private bool BeAValidDate(string value) { DateTime date; return DateTime.TryParse(value, out date); } private bool BeAValidTime(string value) { DateTimeOffset offset; return DateTimeOffset.TryParse(value, out offset); } // new private bool BeGreaterThan(EventViewModel instance, string endTime) { DateTime start = DateTime.Parse(instance.StartDate + " " + instance.StartTime); DateTime end = DateTime.Parse(instance.EndDate + " " + instance.EndTime); return (DateTime.Compare(start, end) &lt;= 0); } } </code></pre> <p>There might be a cleaner/more legant way to do this, but for now, it worksforme.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload