public OFormPart GetFormPartByName(string name, VersionOptions options) { return _contentManager.Query<OFormPart, OFormPartRecord>(options) .Where(f => f.Name == name) .List() .FirstOrDefault(); }
public TimetableAppointmentPart Get(TimetablePart TimetablePart, string slug, VersionOptions versionOptions) { var postSlug = TimetablePart.As<IRoutableAspect>().GetChildPath(slug); return _contentManager.Query(versionOptions, "TimetableAppointment").Join<RoutePartRecord>().Where(rr => rr.Path == postSlug). Join<CommonPartRecord>().Where(cr => cr.Container == TimetablePart.Record.ContentItemRecord).List(). SingleOrDefault().As<TimetableAppointmentPart>(); }
IEnumerable<LocalizationPart> ILocalizationService.GetLocalizations(IContent content, VersionOptions versionOptions) { if (content.ContentItem.Id == 0) return Enumerable.Empty<LocalizationPart>(); var localized = content.As<LocalizationPart>(); var query = versionOptions == null ? _contentManager.Query<LocalizationPart>(localized.ContentItem.ContentType) : _contentManager.Query<LocalizationPart>(versionOptions, localized.ContentItem.ContentType); int contentItemId = localized.ContentItem.Id; if (localized.HasTranslationGroup) { int masterContentItemId = localized.MasterContentItem.ContentItem.Id; query = query.Where<LocalizationPartRecord>(l => l.Id != contentItemId // Exclude the content && (l.Id == masterContentItemId || l.MasterContentItemId == masterContentItemId)); } else { query = query.Where<LocalizationPartRecord>(l => l.MasterContentItemId == contentItemId); } // Warning: May contain more than one localization of the same culture. return query.List().ToList(); }
public PostPart Get(int id, VersionOptions versionOptions) { return _contentManager.Query<PostPart, PostPartRecord>(versionOptions) .WithQueryHints(new QueryHints().ExpandRecords<CommonPartRecord>()) .Where(x => x.Id == id) .List() .SingleOrDefault(); }
public IEnumerable<BlogPostPart> Get(BlogPart blogPart, int skip, int count, VersionOptions versionOptions) { return GetBlogQuery(blogPart, versionOptions) .Slice(skip, count) .ToList() .Select(ci => ci.As<BlogPostPart>()); }
public IEnumerable<ForumPart> Get(VersionOptions versionOptions) { return _contentManager.Query<ForumPart, ForumPartRecord>(versionOptions) .Join<RoutePartRecord>() .OrderBy(br => br.Title) .List(); }
public PostPart GetPositional(ThreadPart threadPart, bool includeInappropriate, VersionOptions versionOptions, ThreadPostPositional positional) { var query = GetParentQuery(threadPart, versionOptions); if (positional == ThreadPostPositional.First) query = query.OrderBy(o => o.PublishedUtc); if (positional == ThreadPostPositional.Latest) query = query.OrderByDescending(o => o.PublishedUtc ); if (!includeInappropriate) { var postPart = query.Join<PostPartRecord>().Where(post => post.IsInappropriate == false); return postPart .ForPart<PostPart>() .Slice(1) .SingleOrDefault(); } // else return query.ForPart<PostPart>() .Slice(1) .SingleOrDefault(); }
public IEnumerable<SeasonPart> Get(VersionOptions versionOptions) { return _contentManager.Query<SeasonPart, SeasonPartRecord>(versionOptions) .Join<TitlePartRecord>() .OrderBy(br => br.Title) .List(); }
public IEnumerable<ForumPart> GetForumsForCategory(ForumCategoryPart forumCategoryPart, int skip, int count, VersionOptions versionOptions) { var forums = _contentManager.Query<ForumPart, ForumPartRecord>(versionOptions) .OrderBy(fp => fp.Weight) .WithQueryHints(new QueryHints().ExpandRecords<CommonPartRecord, TitlePartRecord>()) .Join<CommonPartRecord>() .Where(cpr => cpr.Container.Id == forumCategoryPart.Id).Slice(skip, count).ToList(); /* * var forumIds = _categoryToForumMappingRepository.Table.Where(rec => rec.ForumCategoryPartRecord.Id == forumCategoryPart.Id).Select(rec => rec.ForumPartRecord.Id).ToList(); var forums = _contentManager.Query<ForumPart, ForumPartRecord>(versionOptions).OrderByDescending(fpr => fpr.Weight).Where(forum => forumIds.Contains(forumCategoryPart.Id)).Slice(skip, count).ToList(); */ /* return GetParentQuery(forumCategoryPart, versionOptions) .Join<ThreadPartRecord>() .OrderByDescending(o => o.IsSticky) .Join<CommonPartRecord>() .OrderByDescending(o => o.ModifiedUtc) .ForPart<ThreadPart>() .Slice(skip, count) .ToList(); */ return forums; }
public BlogPostPart Get(BlogPart blogPart, string slug, VersionOptions versionOptions) { var postPath = blogPart.As<IRoutableAspect>().GetChildPath(slug); return _contentManager.Query(versionOptions, "BlogPost").Join<RoutePartRecord>().Where(rr => rr.Path == postPath). Join<CommonPartRecord>().Where(cr => cr.Container == blogPart.Record.ContentItemRecord).List(). SingleOrDefault().As<BlogPostPart>(); }
public IEnumerable<ForumPart> Get(VersionOptions versionOptions) { return _contentManager.Query<ForumPart, ForumPartRecord>(versionOptions) .WithQueryHints(new QueryHints().ExpandRecords<AutoroutePartRecord, TitlePartRecord, CommonPartRecord>()) .OrderBy(o => o.Weight) .List() .ToList(); }
public ForumPart Get(int id, VersionOptions versionOptions) { return _contentManager.Query<ForumPart, ForumPartRecord>(versionOptions) .WithQueryHints(new QueryHints().ExpandRecords<AutoroutePartRecord, TitlePartRecord, CommonPartRecord>()) .Where(x => x.Id == id) .List() .SingleOrDefault(); }
public IEnumerable<HotelPart> Get( DestinationPart destinationPart, int skip, int count, VersionOptions versionOptions) { return GetHotelQuery(destinationPart, versionOptions).Slice(skip, count).ToList().Select( ci => ci.As<HotelPart>()); }
public IEnumerable<ThreadPart> Get(ForumPart forumPart, VersionOptions versionOptions) { return GetForumQuery(forumPart, versionOptions) .OrderByDescending(cr => cr.CreatedUtc) .ForPart<ThreadPart>() .List(); }
private string GetContentType(int id, ContentItem item, VersionOptions options) { if (item != null) { return item.ContentType; } return (options.VersionRecordId == 0) ? String.Format("Content item: {0} is not published.", id) : "Unknown content type."; }
public IEnumerable<CalendarPart> Get(VersionOptions versionOptions) { return _contentManager .Query<CalendarPart>(versionOptions ?? VersionOptions.Latest) .Join<CalendarPartRecord>() .List<CalendarPart>() .OrderBy(br => br.Title); }
public int GetTaggedContentItemCount(int tagId, VersionOptions options) { return _orchardServices.ContentManager .Query<TagsPart, TagsPartRecord>() .Where(tpr => tpr.Tags.Any(tr => tr.TagRecord.Id == tagId)) .Join<MediaPartRecord>() .Count(); }
public ThreadPart Get(int id, bool includeInappropriate, VersionOptions versionOptions) { var threadPart = _contentManager.Query<ThreadPart, ThreadPartRecord>(versionOptions); if ( includeInappropriate == false ) { threadPart = threadPart.Where(o => o.IsInappropriate == false); } return threadPart.WithQueryHints(new QueryHints().ExpandRecords<AutoroutePartRecord, TitlePartRecord, CommonPartRecord>()).Where(x => x.Id == id).Slice(1).SingleOrDefault(); }
public IEnumerable<WidgetExPart> GetWidgets(int hostId, VersionOptions versionOptions = null) { versionOptions = versionOptions ?? VersionOptions.Published; return _contentManager .Query<WidgetExPart, WidgetExPartRecord>() .ForVersion(versionOptions) .Where(x => x.HostId == hostId) .List(); }
public IEnumerable<AddressPart> GetAddressParts(VersionOptions version = null) { version = version ?? VersionOptions.Latest; var data = _contentManager .Query<AddressPart>(version) .List<AddressPart>() .OrderBy(x => x.LocationName); return data; }
public IEnumerable<IContent> GetTaggedContentItems(int tagId, int skip, int take, VersionOptions options) { return _orchardServices.ContentManager .Query<TagsPart, TagsPartRecord>() .Where(tpr => tpr.Tags.Any(tr => tr.TagRecord.Id == tagId)) .Join<CommonPartRecord>().OrderByDescending(x => x.CreatedUtc) .Join<MediaPartRecord>() .Slice(skip, take); }
public IEnumerable<ForumPart> GetForumsForCategory(ForumCategoryPart forumCategoryPart, VersionOptions versionOptions) { return _contentManager.Query<ForumPart, ForumPartRecord>(versionOptions) .WithQueryHints(new QueryHints().ExpandRecords<AutoroutePartRecord, TitlePartRecord, CommonPartRecord>()) .OrderBy( fp=>fp.Weight) .Join<CommonPartRecord>() .Where( cpr=>cpr.Container.Id == forumCategoryPart.Id) .List(); }
public IEnumerable<PostPart> Get(ThreadPart threadPart, int skip, int count, VersionOptions versionOptions) { return _contentManager .Query(versionOptions, ContentPartConstants.Post) .Join<CommonPartRecord>().Where(cpr => cpr.Container == threadPart.ContentItem.Record) .Slice(skip, count) .ToList() .Select(ci => ci.As<PostPart>()); }
private IContentQuery<ContentItem, CommonPartRecord> GetSeasonQuery(ContentPart<SeasonPartRecord> season, VersionOptions versionOptions) { int currentCultureId = _cultureManager.GetCultureByName(Services.WorkContext.CurrentCulture).Id; return _contentManager.Query(versionOptions, "Category") .Join<LocalizationPartRecord>().Where(lr => lr.CultureId == currentCultureId) .Join<CommonPartRecord>().Where( cr => cr.Container == season.Record.ContentItemRecord).OrderByDescending(cr => cr.CreatedUtc) .WithQueryHintsFor("Category"); }
public ThreadPart Get(int forumId, int threadId, VersionOptions versionOptions) { return _contentManager.Query<CommonPart, CommonPartRecord>(versionOptions) .Where(cpr => cpr.Container.Id == forumId) .Join<ThreadPartRecord>() .Where(o => o.Id == threadId) .WithQueryHints(new QueryHints().ExpandRecords<AutoroutePartRecord, TitlePartRecord, CommonPartRecord>()) .ForPart<ThreadPart>() .Slice(1) .SingleOrDefault(); }
public IEnumerable<ThreadPart> Get(ForumPart forumPart, int skip, int count, VersionOptions versionOptions) { return GetParentQuery(forumPart, versionOptions) .Join<ThreadPartRecord>() .OrderByDescending(o => o.IsSticky) .Join<CommonPartRecord>() .OrderByDescending(o => o.ModifiedUtc) .ForPart<ThreadPart>() .Slice(skip, count) .ToList(); }
public static IEnumerable<LocalizationPart> GetAvailableLocalizations(this ILocalizationService localizationService, IContent content, VersionOptions versionOptions, CultureRecord siteCulture) { return localizationService.GetLocalizations(content.ContentItem, versionOptions) .Select(c => { var localized = c.ContentItem.As<LocalizationPart>(); if (localized.Culture == null) localized.Culture = siteCulture; return c; }).ToList(); }
public CalendarPart GetCalendar(string id, VersionOptions versionOptions) { var itemPart = _contentManager.Query<IdentityPart, IdentityPartRecord>(versionOptions ?? VersionOptions.Latest) .Where(i => i.Identifier.Equals(id, StringComparison.OrdinalIgnoreCase)) .Join<IdentityPartRecord>() .Join<CalendarPartRecord>() .List<CalendarPart>() .SingleOrDefault(); return itemPart; }
public new ContentItem Get(int id, VersionOptions options, QueryHints hints) { return _performanceMonitor.PublishTimedAction(() => base.Get(id, options, hints), (r, t) => new ContentManagerMessage { ContentId = id, ContentType = GetContentType(id, r, options), Name = r.GetContentName(), Duration = t.Duration, //VersionOptions = options }, TimelineCategories.ContentManagement, r => "Get: " + GetContentType(id, r, options), r=> r.GetContentName()).ActionResult; }
public ContentItem Get(string id, VersionOptions versionOptions) { int recordId; var isRecordId = int.TryParse(id, out recordId); if (isRecordId) { return _contentManager.Get(recordId, VersionOptions.Published); } var itemPart = GetCalendar(id,versionOptions); return itemPart == null ? null : itemPart.ContentItem; }
public static IContentQuery <TPart, TRecord> Query <TPart, TRecord>(this IContentManager manager, VersionOptions options) where TPart : ContentPart <TRecord> where TRecord : ContentPartRecord { return(manager.Query().ForPart <TPart>().ForVersion(options).Join <TRecord>()); }
public IHqlQuery ForVersion(VersionOptions options) { _versionOptions = options; return(this); }
public static IContentQuery <ContentItem> Query(this IContentManager manager, VersionOptions options, params string[] contentTypeNames) { return(manager.Query().ForVersion(options).ForType(contentTypeNames)); }
/* Query(VersionOptions options) */ public static IContentQuery <ContentItem> Query(this IContentManager manager, VersionOptions options) { return(manager.Query().ForVersion(options)); }
public virtual ContentItem Get(int id, VersionOptions options) { return(Get(id, options, QueryHints.Empty)); }
public static T Get <T>(this IContentManager manager, int id, VersionOptions options, QueryHints hints) where T : class, IContent { var contentItem = manager.Get(id, options, hints); return(contentItem == null ? null : contentItem.Get <T>()); }
public static void Create(this IContentManager manager, IContent content, VersionOptions options) { manager.Create(content.ContentItem, options); }
public static ContentItem Create(this IContentManager manager, string contentType, VersionOptions options) { return(manager.Create <ContentItem>(contentType, options, init => { })); }
public IEnumerable <T> GetMany <T>(IEnumerable <int> ids, VersionOptions options, QueryHints hints) where T : class, IContent { var contentItemVersionRecords = GetManyImplementation(hints, (contentItemCriteria, contentItemVersionCriteria) => { contentItemCriteria.Add(Restrictions.In("Id", ids.ToArray())); if (options.IsPublished) { contentItemVersionCriteria.Add(Restrictions.Eq("Published", true)); } else if (options.IsLatest) { contentItemVersionCriteria.Add(Restrictions.Eq("Latest", true)); } else if (options.IsDraft && !options.IsDraftRequired) { contentItemVersionCriteria.Add( Restrictions.And(Restrictions.Eq("Published", false), Restrictions.Eq("Latest", true))); } else if (options.IsDraft || options.IsDraftRequired) { contentItemVersionCriteria.Add(Restrictions.Eq("Latest", true)); } }); var itemsById = contentItemVersionRecords .Select(r => Get(r.ContentItemRecord.Id, options.IsDraftRequired ? options : VersionOptions.VersionRecord(r.Id))) .GroupBy(ci => ci.Id) .ToDictionary(g => g.Key); return(ids.SelectMany(id => { IGrouping <int, ContentItem> values; return itemsById.TryGetValue(id, out values) ? values : Enumerable.Empty <ContentItem>(); }).AsPart <T>().ToArray()); }
private IEnumerable <ContentItem> Slice(int skip, int count) { var criteria = BindItemVersionCriteria(); criteria.ApplyVersionOptionsRestrictions(_versionOptions); criteria.SetFetchMode("ContentItemRecord", FetchMode.Eager); criteria.SetFetchMode("ContentItemRecord.ContentType", FetchMode.Eager); // TODO: put 'removed false' filter in place if (skip != 0) { criteria = criteria.SetFirstResult(skip); } if (count != 0) { criteria = criteria.SetMaxResults(count); } return(criteria .List <ContentItemVersionRecord>() .Select(x => ContentManager.Get(x.ContentItemRecord.Id, _versionOptions != null && _versionOptions.IsDraftRequired ? _versionOptions : VersionOptions.VersionRecord(x.Id))) .ToReadOnlyCollection()); }
internal static void ApplyVersionOptionsRestrictions(this ICriteria criteria, VersionOptions versionOptions) { if (versionOptions == null) { criteria.Add(Restrictions.Eq("Published", true)); } else if (versionOptions.IsPublished) { criteria.Add(Restrictions.Eq("Published", true)); } else if (versionOptions.IsLatest) { criteria.Add(Restrictions.Eq("Latest", true)); } else if (versionOptions.IsDraft && !versionOptions.IsDraftRequired) { criteria.Add(Restrictions.And( Restrictions.Eq("Latest", true), Restrictions.Eq("Published", false))); } else if (versionOptions.IsDraft || versionOptions.IsDraftRequired) { criteria.Add(Restrictions.Eq("Latest", true)); } else if (versionOptions.IsAllVersions) { // no-op... all versions will be returned by default } else { throw new ApplicationException("Invalid VersionOptions for content query"); } }
public static IContentQuery <TPart> Query <TPart>(this IContentManager manager, VersionOptions options) where TPart : ContentPart { return(manager.Query().ForPart <TPart>().ForVersion(options)); }
public void ForVersion(VersionOptions options) { _versionOptions = options; }
public virtual ContentItem Get(int id, VersionOptions options, QueryHints hints) { var session = _contentManagerSession(); ContentItem contentItem; ContentItemVersionRecord versionRecord = null; // obtain the root records based on version options if (options.VersionRecordId != 0) { // short-circuit if item held in session if (session.RecallVersionRecordId(options.VersionRecordId, out contentItem)) { return(contentItem); } versionRecord = _contentItemVersionRepository.Get(options.VersionRecordId); } else if (session.RecallContentRecordId(id, out contentItem)) { // try to reload a previously loaded published content item if (options.IsPublished) { return(contentItem); } versionRecord = contentItem.VersionRecord; } else { // do a query to load the records in case Get is called directly var contentItemVersionRecords = GetManyImplementation(hints, (contentItemCriteria, contentItemVersionCriteria) => { contentItemCriteria.Add(Restrictions.Eq("Id", id)); if (options.IsPublished) { contentItemVersionCriteria.Add(Restrictions.Eq("Published", true)); } else if (options.IsLatest) { contentItemVersionCriteria.Add(Restrictions.Eq("Latest", true)); } else if (options.IsDraft && !options.IsDraftRequired) { contentItemVersionCriteria.Add( Restrictions.And(Restrictions.Eq("Published", false), Restrictions.Eq("Latest", true))); } else if (options.IsDraft || options.IsDraftRequired) { contentItemVersionCriteria.Add(Restrictions.Eq("Latest", true)); } contentItemVersionCriteria.SetFetchMode("ContentItemRecord", FetchMode.Eager); contentItemVersionCriteria.SetFetchMode("ContentItemRecord.ContentType", FetchMode.Eager); contentItemVersionCriteria.SetMaxResults(1); }); versionRecord = contentItemVersionRecords.FirstOrDefault(); } // no record means content item is not in db if (versionRecord == null) { // check in memory var record = _contentItemRepository.Get(id); if (record == null) { return(null); } versionRecord = GetVersionRecord(options, record); if (versionRecord == null) { return(null); } } // return item if obtained earlier in session if (session.RecallVersionRecordId(versionRecord.Id, out contentItem)) { if (options.IsDraftRequired && versionRecord.Published) { return(BuildNewVersion(contentItem)); } return(contentItem); } // allocate instance and set record property contentItem = New(versionRecord.ContentItemRecord.ContentType.Name); contentItem.VersionRecord = versionRecord; // store in session prior to loading to avoid some problems with simple circular dependencies session.Store(contentItem); // create a context with a new instance to load var context = new LoadContentContext(contentItem); // invoke handlers to acquire state, or at least establish lazy loading callbacks Handlers.Invoke(handler => handler.Loading(context), Logger); Handlers.Invoke(handler => handler.Loaded(context), Logger); // when draft is required and latest is published a new version is appended if (options.IsDraftRequired && versionRecord.Published) { contentItem = BuildNewVersion(context.ContentItem); } return(contentItem); }
public static IContentQuery <TPart> Query <TPart>(this IContentManager manager, VersionOptions options, params string[] contentTypeNames) where TPart : ContentPart { return(manager.Query().ForPart <TPart>().ForVersion(options).ForType(contentTypeNames)); }
public static T Create <T>(this IContentManager manager, string contentType, VersionOptions options) where T : class, IContent { return(manager.Create <T>(contentType, options, init => { })); }
IContentQuery <T> IContentQuery <T> .ForVersion(VersionOptions options) { _query.ForVersion(options); return(this); }
public ContentItem Get(string id, VersionOptions versionOptions, string contentTypeHint = null) { var contentIdentity = new ContentIdentity(id); // lookup in local cache if (_identities.ContainsKey(contentIdentity)) { if (_draftVersionRecordIds.ContainsKey(_identities[contentIdentity])) { //draft was previously created. Recall. versionOptions = VersionOptions.VersionRecord(_draftVersionRecordIds[_identities[contentIdentity]]); } var result = _contentManager.Get(_identities[contentIdentity], versionOptions); // if two identities are conflicting, then ensure that there types are the same // e.g., importing a blog as home page (alias=) and the current home page is a page, the blog // won't be imported, and blog posts will be attached to the page if (contentTypeHint == null || result.ContentType == contentTypeHint) { return(result); } } ContentItem existingItem = _contentManager.ResolveIdentity(contentIdentity); //ensure we have the correct version if (existingItem != null) { existingItem = _contentManager.Get(existingItem.Id, versionOptions); } if (existingItem == null && _identities.ContainsKey(contentIdentity)) { existingItem = _contentManager.Get(_identities[contentIdentity], versionOptions); } if (existingItem != null) { _identities[contentIdentity] = existingItem.Id; if (versionOptions.IsDraftRequired) { _draftVersionRecordIds[existingItem.Id] = existingItem.VersionRecord.Id; } return(existingItem); } //create item if not found and draft was requested, or it is found later in the import queue if (versionOptions.IsDraftRequired || _allIdentitiesForImportStatus.ContainsKey(contentIdentity)) { var contentType = _contentTypes.ContainsKey(contentIdentity) ? _contentTypes[contentIdentity] : contentTypeHint; if (!_contentTypes.ContainsKey(contentIdentity)) { throw new ArgumentException("Unknown content type for " + id); } var contentItem = _contentManager.Create(contentType, VersionOptions.Draft); _identities[contentIdentity] = contentItem.Id; //store versionrecordid in case a draft is requested again _draftVersionRecordIds[contentItem.Id] = contentItem.VersionRecord.Id; //add the requested item as a dependency if it is not the currently running item if (_allIdentitiesForImportStatus.ContainsKey(contentIdentity) && !_allIdentitiesForImportStatus[contentIdentity]) { _dependencyIdentities.Enqueue(contentIdentity); } return(contentItem); } return(null); }
public async Task <ContentItem> GetAsync(string contentItemId, VersionOptions options) { ContentItem contentItem = null; if (options.IsLatest) { contentItem = await _session .Query <ContentItem, ContentItemIndex>() .Where(x => x.ContentItemId == contentItemId && x.Latest == true) .FirstOrDefaultAsync(); } else if (options.IsDraft && !options.IsDraftRequired) { contentItem = await _session .Query <ContentItem, ContentItemIndex>() .Where(x => x.ContentItemId == contentItemId && x.Published == false && x.Latest == true) .FirstOrDefaultAsync(); } else if (options.IsDraft || options.IsDraftRequired) { // Loaded whatever is the latest as it will be cloned contentItem = await _session .Query <ContentItem, ContentItemIndex>() .Where(x => x.ContentItemId == contentItemId && x.Latest == true) .FirstOrDefaultAsync(); } else if (options.IsPublished) { // If the published version is requested and is already loaded, we can // return it right away if (_contentManagerSession.RecallPublishedItemId(contentItemId, out contentItem)) { return(contentItem); } contentItem = await _session .Query <ContentItem, ContentItemIndex>() .Where(x => x.ContentItemId == contentItemId && x.Published == true) .FirstOrDefaultAsync(); } if (contentItem == null) { if (!options.IsDraftRequired) { return(null); } } // Return item if obtained earlier in session // If IsPublished is required then the test has already been checked before ContentItem recalled = null; if (!_contentManagerSession.RecallVersionId(contentItem.Id, out recalled)) { // store in session prior to loading to avoid some problems with simple circular dependencies _contentManagerSession.Store(contentItem); // create a context with a new instance to load var context = new LoadContentContext(contentItem); // invoke handlers to acquire state, or at least establish lazy loading callbacks Handlers.Invoke(handler => handler.Loading(context), _logger); Handlers.Reverse().Invoke(handler => handler.Loaded(context), _logger); contentItem = context.ContentItem; } else { contentItem = recalled; } if (options.IsDraftRequired) { // When draft is required and latest is published a new version is added if (contentItem.Published) { // Save the previous version _session.Save(contentItem); contentItem = await BuildNewVersionAsync(contentItem); } // Save the new version _session.Save(contentItem); } return(contentItem); }