Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

Commit

Permalink
feat(Helpers): Add an extension that allows to get the contents of an…
Browse files Browse the repository at this point in the history
…y IContainer.
  • Loading branch information
Xceno committed Jul 14, 2018
1 parent ac7f1ec commit 191f9a6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Helpers/Content/ContentManagerExtensions.cs
@@ -0,0 +1,24 @@
namespace Orchard.Tools.Helpers.Content {
using System.Collections.Generic;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Records;
using Orchard.Core.Common.Models;
using Orchard.Core.Containers.Models;

public static class ContentManagerExtensions {
/// <summary>
/// Queries the database for the given container and returns a list of the container contents with the specified Part.
/// </summary>
public static IEnumerable<TPart> GetContainerContentsOfType<TPart, TRecord>(this IContentManager contentManager, int containerId, VersionOptions versionOptions = null)
where TPart : ContentPart<TRecord>
where TRecord : ContentPartRecord {
return contentManager
.Query<TPart, TRecord>(versionOptions ?? VersionOptions.Published)
.Join<CommonPartRecord>()
.Where(x => x.Container != null && x.Container.Id == containerId)
.Join<ContainablePartRecord>()
.OrderByDescending(x => x.Position)
.List();
}
}
}
1 change: 1 addition & 0 deletions Orchard.Tools.csproj
Expand Up @@ -111,6 +111,7 @@
<ItemGroup>
<Compile Include="Commands\CodeGenerationCommands.cs" />
<Compile Include="Commands\TemplateInfo.cs" />
<Compile Include="Helpers\Content\ContentManagerExtensions.cs" />
<Compile Include="Helpers\Html\HtmlHelperExtensions.cs" />
<Compile Include="Helpers\Long\LongExtensions.cs" />
<Compile Include="Helpers\Reflection\ObjectExtensions.cs" />
Expand Down

0 comments on commit 191f9a6

Please sign in to comment.