using Nop.Services.Authentication.MultiFactor; using Nop.Web.Areas.Admin.Infrastructure.Mapper.Extensions; using Nop.Web.Areas.Admin.Models.MultiFactorAuthentication; using Nop.Web.Framework.Models.Extensions; namespace Nop.Web.Areas.Admin.Factories; /// /// Represents the multi-factor authentication method model factory implementation /// public partial class MultiFactorAuthenticationMethodModelFactory : IMultiFactorAuthenticationMethodModelFactory { #region Fields protected readonly IMultiFactorAuthenticationPluginManager _multiFactorAuthenticationPluginManager; #endregion #region Ctor public MultiFactorAuthenticationMethodModelFactory(IMultiFactorAuthenticationPluginManager multiFactorAuthenticationPluginManager) { _multiFactorAuthenticationPluginManager = multiFactorAuthenticationPluginManager; } #endregion #region Methods /// /// Prepare multi-factor authentication method search model /// /// Multi-factor authentication method search model /// Multi-factor authentication method search model public virtual MultiFactorAuthenticationMethodSearchModel PrepareMultiFactorAuthenticationMethodSearchModel( MultiFactorAuthenticationMethodSearchModel searchModel) { ArgumentNullException.ThrowIfNull(searchModel); //prepare page parameters searchModel.SetGridPageSize(); return searchModel; } /// /// Prepare paged multi-factor authentication method list model /// /// Multi-factor authentication method search model /// /// A task that represents the asynchronous operation /// The task result contains the multi-factor authentication method list model /// public virtual async Task PrepareMultiFactorAuthenticationMethodListModelAsync(MultiFactorAuthenticationMethodSearchModel searchModel) { ArgumentNullException.ThrowIfNull(searchModel); //get multi-factor authentication methods var multiFactorAuthenticationMethods = (await _multiFactorAuthenticationPluginManager.LoadAllPluginsAsync()).ToPagedList(searchModel); //prepare grid model var model = new MultiFactorAuthenticationMethodListModel().PrepareToGrid(searchModel, multiFactorAuthenticationMethods, () => { //fill in model values from the entity return multiFactorAuthenticationMethods.Select(method => { //fill in model values from the entity var multiFactorAuthenticationMethodModel = method.ToPluginModel(); //fill in additional values (not existing in the entity) multiFactorAuthenticationMethodModel.IsActive = _multiFactorAuthenticationPluginManager.IsPluginActive(method); multiFactorAuthenticationMethodModel.ConfigurationUrl = method.GetConfigurationPageUrl(); return multiFactorAuthenticationMethodModel; }); }); return model; } #endregion }