Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing GetDefaultMessageTemplates #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using FluentValidation;
using FluentValidation;
using FluentValidation.Resources;
using FluentValidation.Validators;
using System;
Expand All @@ -8,23 +8,24 @@ namespace Arc4u.FluentValidation.Rules

internal class IsUtcDateOnlyRuleValidator<T, TProperty> : PropertyValidator<T, TProperty> where T : class where TProperty : struct
{

static string ruleName = "IsUtcDateOnlyRuleValidator";
public override string Name => ruleName;

static IsUtcDateOnlyRuleValidator()
{
var lgMgr = ValidatorOptions.Global.LanguageManager as LanguageManager;
lgMgr?.AddTranslation("en", ruleName, "Property must be a DateTime with no Time {PropertyValue}.");
}

public override string Name => ruleName;

public override bool IsValid(ValidationContext<T> context, TProperty value)
{
var dt = value as DateTime?;

return dt.HasValue && dt.Value.TimeOfDay.Equals(TimeSpan.Zero);
}


protected override string GetDefaultMessageTemplate(string errorCode)
{
return Localized(errorCode, Name);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using FluentValidation;
using FluentValidation;
using FluentValidation.Resources;
using FluentValidation.Validators;
using System;
Expand All @@ -7,23 +7,24 @@ namespace Arc4u.FluentValidation.Rules
{
internal class IsUtcDateTimeRuleValidator<T, TProperty> : PropertyValidator<T, TProperty> where T : class where TProperty : struct
{

static string ruleName = "IsUtcDateTimeRuleValidator";
public override string Name => ruleName;

static IsUtcDateTimeRuleValidator()
{
var lgMgr = ValidatorOptions.Global.LanguageManager as LanguageManager;
lgMgr?.AddTranslation("en", ruleName, "Property must be a DateTime and in Utc {PropertyValue}.");
}

public override string Name => ruleName;

public override bool IsValid(ValidationContext<T> context, TProperty value)
{
var dt = value as DateTime?;
return dt is { Kind: DateTimeKind.Utc };
}

return dt.HasValue && dt.Value.Kind == DateTimeKind.Utc;


protected override string GetDefaultMessageTemplate(string errorCode)
{
return Localized(errorCode, Name);
}
}
}