Exemplo n.º 1
0
        public void SetAppIdForInstance(IInstanceInfo instance, IAppEnvironment env, int?appId, Log parentLog)
        {
            Log.Add($"SetAppIdForInstance({instance.Id}, -, appid: {appId})");
            // Reset temporary template
            ContentGroupManager.ClearPreviewTemplate(instance.Id);

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

            var module = (instance as EnvironmentInstance <ModuleInfo>).Original;
            var zoneId = env.ZoneMapper.GetZoneId(module.OwnerPortalID);

            if (appId == 0 || !appId.HasValue)
            {
                DnnStuffToRefactor.UpdateInstanceSettingForAllLanguages(instance.Id, Settings.AppNameString, null, Log);
            }
            else
            {
                var appName = ((BaseCache)DataSource.GetCache(0, 0)).ZoneApps[zoneId].Apps[appId.Value];
                DnnStuffToRefactor.UpdateInstanceSettingForAllLanguages(instance.Id, Settings.AppNameString, appName, Log);
            }

            // Change to 1. available template if app has been set
            if (appId.HasValue)
            {
                var app          = App.LightWithoutData(new DnnTenant(null), zoneId, appId.Value, parentLog: Log);
                var templateGuid = app.TemplateManager.GetAllTemplates().FirstOrDefault(t => !t.IsHidden)?.Guid;
                if (templateGuid.HasValue)
                {
                    ContentGroupManager.SetPreviewTemplate(instance.Id, templateGuid.Value);
                }
            }
        }
 protected override void SavePreviewTemplateId(Guid templateGuid)
 => ContentGroupManager.SetPreviewTemplate(ModuleId, templateGuid);