-
Notifications
You must be signed in to change notification settings - Fork 526
Expand file tree
/
Copy pathLanguageValidator.cs
More file actions
40 lines (37 loc) · 1.49 KB
/
LanguageValidator.cs
File metadata and controls
40 lines (37 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using FluentValidation;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Infrastructure.Validators;
using Grand.Web.Admin.Models.Localization;
using System.Globalization;
namespace Grand.Web.Admin.Validators.Localization;
public class LanguageValidator : BaseGrandValidator<LanguageModel>
{
public LanguageValidator(
IEnumerable<IValidatorConsumer<LanguageModel>> validators,
ITranslationService translationService)
: base(validators)
{
RuleFor(x => x.Name).NotEmpty()
.WithMessage(translationService.GetResource("Admin.Configuration.Languages.Fields.Name.Required"));
RuleFor(x => x.LanguageCulture)
.Must(x =>
{
try
{
//create a CultureInfo object
var culture = new CultureInfo(x);
return culture != null;
}
catch
{
return false;
}
})
.WithMessage(
translationService.GetResource("Admin.Configuration.Languages.Fields.LanguageCulture.Validation"));
RuleFor(x => x.UniqueSeoCode).NotEmpty()
.WithMessage(translationService.GetResource("Admin.Configuration.Languages.Fields.UniqueSeoCode.Required"));
RuleFor(x => x.UniqueSeoCode).Length(2)
.WithMessage(translationService.GetResource("Admin.Configuration.Languages.Fields.UniqueSeoCode.Length"));
}
}