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; } }
protected override ActionResult <TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings) { var nodes = new TreeNodeCollection(); if (id == Constants.System.RootString) { nodes.AddRange(_relationService.GetAllRelationTypes() .Select(rt => CreateTreeNode(rt.Id.ToString(), id, queryStrings, rt.Name, "icon-trafic", hasChildren: false))); } return(nodes); }
public ContentRelationsDto GetRelations( string section, string treeType, int parentId ) { var treeNodeType = new TreeNodeType(section, treeType); var fromContentTreeNodeType = new TreeNodeType(null, treeType); var fromType = UmbracoObjectTypes.Unknown; if (( !Mappings.TreeNodeObjectTypes.TryGetValue(treeNodeType, out fromType) && !Mappings.TreeNodeObjectTypes.TryGetValue(fromContentTreeNodeType, out fromType) ) || fromType == UmbracoObjectTypes.Unknown ) { throw new Exception("Cannot get relation types for unknown object type"); } var entity = entityService.Get(parentId, fromType); object alias = null; entity.AdditionalData.TryGetValue("Alias", out alias); var typeConfig = RelationEditor.Configuration.Get(fromType, alias as string); var allRelations = relationService.GetByParentOrChildId(parentId); var allowedObjectTypes = Mappings.AllowedRelations[fromType]; var enabledRelations = typeConfig.EnabledRelations.Select(r => r.Alias).ToArray(); var relationSets = relationService.GetAllRelationTypes() .Where(rt => rt.ParentObjectType == fromType.GetGuid() && enabledRelations.Contains(rt.Alias) && allowedObjectTypes.Any(ar => ar.GetGuid() == rt.ChildObjectType) ) .Select(rt => new RelationSetDto { RelationTypeId = rt.Id, Direction = rt.IsBidirectional ? "bidirectional" : "parentchild", ChildType = Mappings.ObjectTypeTreeTypes[rt.ChildObjectType], Alias = rt.Alias, Name = rt.Name, Relations = allRelations .Where(r => r.RelationTypeId == rt.Id && (rt.IsBidirectional || r.ParentId == parentId) ).OrderBy(d => d.Order()) .Select(r => { int otherId; Guid relatedType; var isParent = r.ParentId == parentId; if (isParent) { otherId = r.ChildId; relatedType = rt.ChildObjectType; } else { otherId = r.ParentId; relatedType = rt.ParentObjectType; } var relEntity = GetEntity(relatedType, otherId); var otherName = relEntity.Name; var fullPath = GetFullPath(relEntity); return(new RelationDto { Readonly = !isParent, ChildId = r.ChildId, FullPath = HttpContext.Current.Server.HtmlEncode(fullPath), ChildName = (configuration.BreadcrumbMode == BreadcrumbMode.ToolTip) ? otherName : HttpContext.Current.Server.HtmlDecode(fullPath), State = RelationStateEnum.Unmodified }); }).ToList() }).ToList(); return(new ContentRelationsDto { ParentId = parentId, ParentType = fromType, ParentAlias = alias as string, Sets = relationSets }); }