Skip to content

Commit

Permalink
Validators.
Browse files Browse the repository at this point in the history
  • Loading branch information
Utar94 committed Jul 18, 2024
1 parent 7a93d6a commit 0316f30
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ public class DateTimeFieldValueValidator : AbstractValidator<DateTime>
{
public DateTimeFieldValueValidator(IDateTimeProperties properties)
{
// TODO(fpion): implement
if (properties.MinimumValue.HasValue)
{
RuleFor(x => x).GreaterThanOrEqualTo(properties.MinimumValue.Value);
}
if (properties.MaximumValue.HasValue)
{
RuleFor(x => x).LessThanOrEqualTo(properties.MaximumValue.Value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ public class DateTimePropertiesValidator : AbstractValidator<IDateTimeProperties
{
public DateTimePropertiesValidator()
{
// TODO(fpion): implement
When(x => x.MinimumValue.HasValue && x.MaximumValue.HasValue, () =>
{
RuleFor(x => x.MinimumValue!.Value).LessThanOrEqualTo(x => x.MaximumValue!.Value);
RuleFor(x => x.MaximumValue!.Value).GreaterThanOrEqualTo(x => x.MinimumValue!.Value);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ public class NumberFieldValueValidator : AbstractValidator<double>
{
public NumberFieldValueValidator(INumberProperties properties)
{
// TODO(fpion): implement
if (properties.MinimumValue.HasValue)
{
RuleFor(x => x).GreaterThanOrEqualTo(properties.MinimumValue.Value);
}
if (properties.MaximumValue.HasValue)
{
RuleFor(x => x).LessThanOrEqualTo(properties.MaximumValue.Value);
}

// ISSUE: https://github.com/Logitar/CMS/issues/28
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ public class NumberPropertiesValidator : AbstractValidator<INumberProperties>
{
public NumberPropertiesValidator()
{
// TODO(fpion): implement
When(x => x.MinimumValue.HasValue && x.MaximumValue.HasValue, () =>
{
RuleFor(x => x.MinimumValue!.Value).LessThanOrEqualTo(x => x.MaximumValue!.Value);
RuleFor(x => x.MaximumValue!.Value).GreaterThanOrEqualTo(x => x.MinimumValue!.Value);
});

// ISSUE: https://github.com/Logitar/CMS/issues/28
}
}

0 comments on commit 0316f30

Please sign in to comment.