/// <summary>
        /// Prepare user search model
        /// </summary>
        /// <param name="searchModel">User search model</param>
        /// <returns>User search model</returns>
        public virtual UserSearchModel PrepareUserSearchModel(UserSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            searchModel.UsernamesEnabled     = _userSettings.UsernamesEnabled;
            searchModel.AvatarEnabled        = _userSettings.AllowUsersToUploadAvatars;
            searchModel.DateOfBirthEnabled   = _userSettings.DateOfBirthEnabled;
            searchModel.CompanyEnabled       = _userSettings.CompanyEnabled;
            searchModel.PhoneEnabled         = _userSettings.PhoneEnabled;
            searchModel.ZipPostalCodeEnabled = _userSettings.ZipPostalCodeEnabled;

            //search registered users by default
            var registeredRole = _userService.GetUserRoleBySystemName(NopUserDefaults.RegisteredRoleName);

            if (registeredRole != null)
            {
                searchModel.SelectedUserRoleIds.Add(registeredRole.Id);
            }

            //prepare available user roles
            _aclSupportedModelFactory.PrepareModelUserRoles(searchModel);

            //prepare page parameters
            searchModel.SetGridPageSize();

            return(searchModel);
        }
Example #2
0
        /// <summary>
        /// Prepare plugin model
        /// </summary>
        /// <param name="model">Plugin model</param>
        /// <param name="pluginDescriptor">Plugin descriptor</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Plugin model</returns>
        public virtual PluginModel PreparePluginModel(PluginModel model, PluginDescriptor pluginDescriptor, bool excludeProperties = false)
        {
            Action <PluginLocalizedModel, int> localizedModelConfiguration = null;

            if (pluginDescriptor != null)
            {
                //fill in model values from the entity
                model = model ?? pluginDescriptor.ToPluginModel(model);

                model.LogoUrl             = PluginManager.GetLogoUrl(pluginDescriptor);
                model.SelectedUserRoleIds = pluginDescriptor.LimitedToUserRoles;
                if (pluginDescriptor.Installed)
                {
                    PrepareInstalledPluginModel(model, pluginDescriptor.Instance());
                }

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    var plugin = pluginDescriptor.Instance();
                    locale.FriendlyName = _localizationService.GetLocalizedFriendlyName(plugin, languageId, false);
                };
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            //prepare model user roles
            _aclSupportedModelFactory.PrepareModelUserRoles(model);

            return(model);
        }