Added new overloads to MediaById and NodeById which take List<object> or params object[] and return DynamicNodeList or DynamicMediaList [new - doesn't support OrderBy,Where etc]
Added to allow retreiving multiple items by id when you know the Ids, e.g.: using MNTP to select nodes and then needing to get them in Razor
This commit is contained in:
@@ -12,6 +12,8 @@ namespace umbraco.MacroEngines
|
||||
{
|
||||
private Dictionary<string, string> _propertyCache;
|
||||
private Media _media;
|
||||
internal DynamicMediaList ownerList;
|
||||
|
||||
public DynamicMedia(int mediaId)
|
||||
{
|
||||
_media = new Media(mediaId);
|
||||
@@ -55,6 +57,7 @@ namespace umbraco.MacroEngines
|
||||
}
|
||||
if (_media != null)
|
||||
{
|
||||
Properties props = _media.GenericProperties;
|
||||
Property prop = _media.getProperty(name);
|
||||
// check for nicer support of Pascal Casing EVEN if alias is camelCasing:
|
||||
if (prop == null && name.Substring(0, 1).ToUpper() == name.Substring(0, 1))
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Dynamic;
|
||||
using System.Collections;
|
||||
using umbraco.cms.businesslogic.media;
|
||||
|
||||
namespace umbraco.MacroEngines
|
||||
{
|
||||
public class DynamicMediaList : DynamicObject, IEnumerable
|
||||
{
|
||||
public IEnumerable<DynamicMedia> Items { get; set; }
|
||||
|
||||
public DynamicMediaList()
|
||||
{
|
||||
Items = new List<DynamicMedia>();
|
||||
}
|
||||
public DynamicMediaList(IEnumerable<DynamicMedia> items)
|
||||
{
|
||||
List<DynamicMedia> list = items.ToList();
|
||||
list.ForEach(node => node.ownerList = this);
|
||||
Items = list;
|
||||
}
|
||||
public DynamicMediaList(IEnumerable<Media> items)
|
||||
{
|
||||
List<DynamicMedia> list = items.Select(x => new DynamicMedia(x)).ToList();
|
||||
list.ForEach(node => node.ownerList = this);
|
||||
Items = list;
|
||||
}
|
||||
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
return Items.GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -592,6 +592,17 @@ namespace umbraco.MacroEngines
|
||||
{
|
||||
return new DynamicNode(Id);
|
||||
}
|
||||
public DynamicNodeList NodeById(List<object> Ids)
|
||||
{
|
||||
List<DynamicNode> nodes = new List<DynamicNode>();
|
||||
foreach (object eachId in Ids)
|
||||
nodes.Add(new DynamicNode(eachId));
|
||||
return new DynamicNodeList(nodes);
|
||||
}
|
||||
public DynamicNodeList NodeById(params object[] Ids)
|
||||
{
|
||||
return NodeById(Ids.ToList());
|
||||
}
|
||||
public DynamicMedia MediaById(int Id)
|
||||
{
|
||||
return new DynamicMedia(Id);
|
||||
@@ -604,6 +615,17 @@ namespace umbraco.MacroEngines
|
||||
{
|
||||
return new DynamicMedia(Id);
|
||||
}
|
||||
public DynamicMediaList MediaById(List<object> Ids)
|
||||
{
|
||||
List<DynamicMedia> nodes = new List<DynamicMedia>();
|
||||
foreach (object eachId in Ids)
|
||||
nodes.Add(new DynamicMedia(eachId));
|
||||
return new DynamicMediaList(nodes);
|
||||
}
|
||||
public DynamicMediaList MediaById(params object[] Ids)
|
||||
{
|
||||
return MediaById(Ids.ToList());
|
||||
}
|
||||
public int Id
|
||||
{
|
||||
get { if (n == null) return 0; return n.Id; }
|
||||
|
||||
@@ -64,6 +64,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="RazorCore\BaseContext.cs" />
|
||||
<Compile Include="RazorDynamicNode\DynamicMediaList.cs" />
|
||||
<Compile Include="RazorDynamicNode\DynamicNodeList.cs" />
|
||||
<Compile Include="RazorDynamicNode\DynamicNodeWalker.cs" />
|
||||
<Compile Include="RazorDynamicNode\DynamicNodeWhereHelpers.cs" />
|
||||
|
||||
Reference in New Issue
Block a user