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 */);
}
}
}