ToSic.SexyContent.Internal.DnnStuffToRefactor.UpdateModuleSettingForAllLanguages C# (CSharp) Method

UpdateModuleSettingForAllLanguages() public static method

Update a setting for all language-versions of a module
public static UpdateModuleSettingForAllLanguages ( int moduleId, string key, string value ) : void
moduleId int
key string
value string
return void
        public static void UpdateModuleSettingForAllLanguages(int moduleId, string key, string value)
        {
            var moduleController = new ModuleController();

            // Find this module in other languages and update contentGroupGuid
            var originalModule = moduleController.GetModule(moduleId);
            var languages = LocaleController.Instance.GetLocales(originalModule.PortalID);

            if (!originalModule.IsDefaultLanguage && originalModule.DefaultLanguageModule != null)
                originalModule = originalModule.DefaultLanguageModule;

            foreach (var language in languages)
            {
                // Find module for given Culture
                var moduleByCulture = moduleController.GetModuleByCulture(originalModule.ModuleID, originalModule.TabID, originalModule.PortalID, language.Value);

                // Break if no module found
                if (moduleByCulture == null)
                    continue;

                if (value == null)
                    moduleController.DeleteModuleSetting(moduleByCulture.ModuleID, key);
                else
                    moduleController.UpdateModuleSetting(moduleByCulture.ModuleID, key, value);
            }
        }

Usage Example

Example #1
0
        public static void SetAppIdForModule(ModuleInfo module, int?appId)
        {
            //var moduleController = new ModuleController();

            // Reset temporary template
            ContentGroupManager.DeletePreviewTemplateId(module.ModuleID);

            // ToDo: Should throw exception if a real ContentGroup exists

            var zoneId = ZoneHelpers.GetZoneID(module.OwnerPortalID);

            if (appId == 0 || !appId.HasValue)
            {
                //moduleController.DeleteModuleSetting(module.ModuleID, AppNameString);
                DnnStuffToRefactor.UpdateModuleSettingForAllLanguages(module.ModuleID, Settings.AppNameString, null);
            }
            else
            {
                var appName = ((BaseCache)DataSource.GetCache(0, 0)).ZoneApps[zoneId.Value].Apps[appId.Value];
                //moduleController.UpdateModuleSetting(module.ModuleID, AppNameString, appName);
                DnnStuffToRefactor.UpdateModuleSettingForAllLanguages(module.ModuleID, Settings.AppNameString, appName);
            }

            // Change to 1. available template if app has been set
            if (appId.HasValue)
            {
                //var sexyForNewApp = new SxcInstance(zoneId.Value, appId.Value);// 2016-03-26 2dm this used to have a third parameter false = don't enable caching, which hasn't been respected for a while; removed it
                var app       = new App(zoneId.Value, appId.Value, PortalSettings.Current);
                var templates = app.TemplateManager.GetAvailableTemplatesForSelector(module.ModuleID, app.ContentGroupManager).ToList();
                if (templates.Any())
                {
                    app.ContentGroupManager.SetModulePreviewTemplateId(module.ModuleID, templates.First().Guid /* .TemplateId */);
                }
            }
        }
All Usage Examples Of ToSic.SexyContent.Internal.DnnStuffToRefactor::UpdateModuleSettingForAllLanguages