Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

1.4 KB
Raw Blame
using FluentValidation;
using Grand.Business.Core.Interfaces.Cms;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Infrastructure.Validators;
using Grand.Web.AdminShared.Models.Knowledgebase;

namespace Grand.Web.AdminShared.Validators.Knowledgebase;

public class KnowledgebaseArticleModelValidator : BaseGrandValidator<KnowledgebaseArticleModel>
{
    public KnowledgebaseArticleModelValidator(
        IEnumerable<IValidatorConsumer<KnowledgebaseArticleModel>> validators,
        ITranslationService translationService, IKnowledgebaseService knowledgebaseService)
        : base(validators)
    {
        RuleFor(x => x.Name).NotEmpty()
            .WithMessage(
                translationService.GetResource(
                    "Admin.Content.Knowledgebase.KnowledgebaseArticle.Fields.Name.Required"));
        RuleFor(x => x.ParentCategoryId).NotEmpty().WithMessage(
            translationService.GetResource(
                "Admin.Content.Knowledgebase.KnowledgebaseArticle.Fields.ParentCategoryId.Required"));
        RuleFor(x => x.ParentCategoryId).Must(x =>
        {
            var category = knowledgebaseService.GetKnowledgebaseCategory(x);
            if (category != null) return true;

            return false;
        }).WithMessage(
            translationService.GetResource(
                "Admin.Content.Knowledgebase.KnowledgebaseArticle.Fields.ParentCategoryId.MustExist"));
    }
}