Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

ConfigurationValidator.cs

using FluentValidation;
using Nop.Plugin.Widgets.FacebookPixel.Models;
using Nop.Services.Localization;
using Nop.Web.Framework.Validators;

namespace Nop.Plugin.Widgets.FacebookPixel.Validators;

/// 
/// Represents configuration model validator
/// 
public class ConfigurationValidator : BaseNopValidator
{
    #region Ctor

    public ConfigurationValidator(ILocalizationService localizationService)
    {
        //set validation rules
        RuleFor(model => model.PixelId)
            .NotEmpty()
            .WithMessageAwait(localizationService.GetResourceAsync("Plugins.Widgets.FacebookPixel.Configuration.Fields.PixelId.Required"));
        RuleFor(model => model.AccessToken)
            .NotEmpty()
            .WithMessageAwait(localizationService.GetResourceAsync("Plugins.Widgets.FacebookPixel.Configuration.Fields.AccessToken.Required"))
            .When(model => model.ConversionsApiEnabled);
        RuleFor(model => model.UseAdvancedMatching)
            .NotEqual(true)
            .WithMessageAwait(localizationService.GetResourceAsync("Plugins.Widgets.FacebookPixel.Configuration.Fields.UseAdvancedMatching.Forbidden"))
            .When(model => model.PassUserProperties);
        RuleFor(model => model.PassUserProperties)
            .NotEqual(true)
            .WithMessageAwait(localizationService.GetResourceAsync("Plugins.Widgets.FacebookPixel.Configuration.Fields.PassUserProperties.Forbidden"))
            .When(model => model.UseAdvancedMatching);
    }

    #endregion
}