This repository has been archived by the owner on Feb 14, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Helpers): Add an extension that allows to get the contents of an…
…y IContainer.
- Loading branch information
Showing
2 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters