/// <summary> /// Assigns the item global key to the current instance if one does not exist. /// </summary> /// <param name="dbContext">The database context.</param> private void AssignItemGlobalKey(Data.DbContext dbContext) { if (this.ItemGlobalKey.IsNullOrWhiteSpace()) { var rockContext = ( RockContext )dbContext; var contentChannelItemSlugService = new ContentChannelItemSlugService(rockContext); this.ItemGlobalKey = contentChannelItemSlugService.GetUniqueContentSlug(this.Title, null); } }
/// <summary> /// Delete any related slugs. /// </summary> /// <param name="dbContext">The database context.</param> private void DeleteRelatedSlugs(Data.DbContext dbContext) { var rockContext = ( RockContext )dbContext; var contentChannelSlugSerivce = new ContentChannelItemSlugService(rockContext); var slugsToDelete = contentChannelSlugSerivce.Queryable().Where(a => a.ContentChannelItemId == this.Id); if (slugsToDelete.Any()) { dbContext.BulkDelete(slugsToDelete); } }
/// <summary> /// Called after the save operation is executed. /// </summary> protected override void PostSave() { base.PostSave(); var contentChannelItemSerivce = new ContentChannelItemService(RockContext); var contentChannelSlugSerivce = new ContentChannelItemSlugService(RockContext); if (!contentChannelSlugSerivce.Queryable().Any(a => a.ContentChannelItemId == Entity.Id) && contentChannelItemSerivce.Queryable().Any(a => a.Id == Entity.Id)) { contentChannelSlugSerivce.SaveSlug(Entity.Id, Entity.Title, null); } }
/// <summary> /// Posts the save changes. /// </summary> /// <param name="dbContext">The database context.</param> public override void PostSaveChanges(Data.DbContext dbContext) { base.PostSaveChanges(dbContext); var rockContext = ( RockContext )dbContext; var contentChannelItemSerivce = new ContentChannelItemService(rockContext); var contentChannelSlugSerivce = new ContentChannelItemSlugService(rockContext); if (!contentChannelSlugSerivce.Queryable().Any(a => a.ContentChannelItemId == this.Id) && contentChannelItemSerivce.Queryable().Any(a => a.Id == Id)) { contentChannelSlugSerivce.SaveSlug(Id, Title, null); } }