I want to use data from another app like in code
But I want to get appId from app name or folder? Is there any method to get this?
I want to use data from another app like in code
But I want to get appId from app name or folder? Is there any method to get this?
This is my working code with functions for getting AppId:
public int GetAppIdFromName(string appName){
foreach(var app in sxApps()) if (app.Name==appName) return App.AppId;
return -1;
}
public int GetAppIdFromFolder(string appFolder){
foreach(var app in sxApps()) if (app.Folder==appFolder) return App.AppId;
return -1;
}
public List<ToSic.SexyContent.App> sxApps()
{
var zoneId=(int)ToSic.SexyContent.Internal.ZoneHelpers.GetZoneID(Dnn.Module.PortalID);
var eavApps = ((ToSic.Eav.DataSources.Caches.BaseCache)ToSic.Eav.DataSource.GetCache(zoneId, null)).ZoneApps[zoneId].Apps;
var ps = DotNetNuke.Entities.Portals.PortalSettings.Current;
return eavApps.Select<KeyValuePair<int, string>, ToSic.SexyContent.App>(eavApp => new ToSic.SexyContent.App(zoneId, eavApp.Key, ps)).ToList();
}
Is this OK or can be done easyer?
==================== added =======================
I updated 2sxc from 8.7 to 9.30 and this code don't work anymore.
error:
Compiler Error Message: CS1502: The best overloaded method match for 'ToSic.SexyContent.App.App(ToSic.Eav.Apps.Interfaces.ITenant, int, ToSic.Eav.Logging.Simple.Log)' has some invalid arguments
Source Error:
Line 22: return eavApps.Select<KeyValuePair<int, string>, ToSic.SexyContent.App>(eavApp => new ToSic.SexyContent.App(zoneId, eavApp.Key, ps)).ToList();
Can someone help me with converting this to new version? I don't understand how new ITenant work.
============ edit new solution for 2sxc version 9.30 =============
public static List<ToSic.SexyContent.App> sxApps(int portalID)
{
var zm = new ToSic.SexyContent.Environment.Dnn7.ZoneMapper();
var zoneId = zm.GetZoneId(portalID);
var eavApps = ((ToSic.Eav.DataSources.Caches.BaseCache)ToSic.Eav.DataSource.GetCache(zoneId, null)).ZoneApps[zoneId].Apps;
var ps = DotNetNuke.Entities.Portals.PortalSettings.Current;
var tenant = new ToSic.SexyContent.Environment.Dnn7.DnnTenant(ps);
return eavApps.Select<KeyValuePair<int, string>, ToSic.SexyContent.App>(eavApp => new ToSic.SexyContent.App(tenant, eavApp.Key)).ToList();
}
====================== new edit ===================
On version 9.33 stuff brake again... (on 9.32.1 still work)
Compiler Error Message: CS1729: 'ToSic.SexyContent.App' does not contain a constructor that takes 2 arguments
Line 23: return eavApps.Select, ToSic.SexyContent.App>(eavApp => new ToSic.SexyContent.App(tenant, eavApp.Key)).ToList();
anyone know how to fix this?