Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Websilk.Sitefinity {
- public static partial class SitefinityFunctions {
- /* Fetch - ALL */
- private static Type ResolveType(string type) {
- return TypeResolutionService.ResolveType(string.Concat("Telerik.Sitefinity.DynamicTypes.Model.", type));
- }
- public static IQueryable<DynamicContent> GetAllDynamicContentItems(string type) {
- return DynamicModuleManager.GetManager().GetDataItems(ResolveType(type));
- }
- /* Fetch - LIVE RECORDS */
- public static IQueryable<DynamicContent> GetDynamicContentItems(string type, bool mustBePublished = true) {
- return GetAllDynamicContentItems(type).Where(o => (!mustBePublished || o.Visible) && o.Status == ContentLifecycleStatus.Live);
- }
- public static IQueryable<DynamicContent> GetDynamicContentItems(string type, IEnumerable<Guid> ids, bool mustBePublished = true, bool preserveOrder = false)
- {
- var dynamicContentItems = GetDynamicContentItems(type, mustBePublished).Where(o => ids.Contains(o.Id));
- //If you're not asked to preserve the ordering at this point (default), then you can efficiently return a true IQueryable
- if (!preserveOrder)
- {
- return dynamicContentItems;
- }
- //Ordering forces iteration, so has to return a fake IQueryable
- return ids.Select(thisId => dynamicContentItems.SingleOrDefault(o => o.OriginalContentId == thisId)).Where(dynamicContentItem => dynamicContentItem != null).AsQueryable();
- }
- /* Fetch - LIVE RECORDS BY MASTERID */
- public static IQueryable<DynamicContent> GetDynamicContentItemsFromMaster(string type, IEnumerable<Guid> ids, bool mustBePublished = true, bool preserveOrder = false) {
- var dynamicContentItems = GetDynamicContentItems(type, mustBePublished).Where(o => ids.Contains(o.OriginalContentId));
- //If you're not asked to preserve the ordering at this point (default), then you can efficiently return a true IQueryable
- if (!preserveOrder)
- {
- return dynamicContentItems;
- }
- //Ordering forces iteration, so has to return a fake IQueryable
- return ids.Select(thisId => dynamicContentItems.SingleOrDefault(o => o.OriginalContentId == thisId)).Where(dynamicContentItem => dynamicContentItem != null).AsQueryable();
- }
- }
- }
Add Comment
Please, Sign In to add comment