public void Handle(ContentMovedNotification notification) { foreach (var item in notification.MoveInfoCollection.Where(x => x.OriginalPath.Contains(Constants.System.RecycleBinContentString))) { const string relationTypeAlias = Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteAlias; var relations = _relationService.GetByChildId(item.Entity.Id); foreach (var relation in relations.Where(x => x.RelationType.Alias.InvariantEquals(relationTypeAlias))) { _relationService.Delete(relation); } } }
private static void ContentService_Trashing(IContentService sender, MoveEventArgs <IContent> moveEventArgs) { foreach (MoveEventInfo <IContent> trashingEntity in moveEventArgs.MoveInfoCollection) { List <IRelation> relations = RelationService.GetByChildId(trashingEntity.Entity.Id).ToList(); if (relations.Any() == false) { continue; } IEnumerable <IRelationType> relationsTypes = RelationService .GetAllRelationTypes( relations.Select(x => x.RelationTypeId).ToArray()) .Where(x => x.Alias == RelationTypes.BentoItemsAlias); if (!relationsTypes.Any()) { continue; } moveEventArgs.CancelOperation(new EventMessage("Bento setup", $"This content is used in the following places: {string.Join(", ", relations.Select(x => sender.GetById(x.ParentId).Name))} (delete failed)", EventMessageType.Error)); break; } }
//[EnsureUserPermissionForContent("childId")] public IEnumerable <RelationDisplay> GetByChildId(int childId, string relationTypeAlias = "") { IRelation[] relations = _relationService.GetByChildId(childId).ToArray(); if (relations.Any() == false) { return(Enumerable.Empty <RelationDisplay>()); } if (string.IsNullOrWhiteSpace(relationTypeAlias) == false) { return (_umbracoMapper.MapEnumerable <IRelation, RelationDisplay>( relations.Where(x => x.RelationType.Alias.InvariantEquals(relationTypeAlias))).WhereNotNull()); } return(_umbracoMapper.MapEnumerable <IRelation, RelationDisplay>(relations).WhereNotNull()); }