public IRelation GetPageLockDetails(int pageId)
        {
            var existingLocks = _relationService.GetByParentOrChildId(pageId, ContentGuardRelationTypeAlias);

            return(existingLocks != null && existingLocks.Any()
                ? existingLocks.FirstOrDefault(x => x.ParentId.Equals(pageId))
                : null);
        }
示例#2
0
 private void ContentService_Trashing(IContentService sender, MoveEventArgs<IContent> e)
 {
     //relationService = ApplicationContext.Current.Services.RelationService;
     foreach (var entity in e.MoveInfoCollection)
     {
         if (relationService.GetByParentOrChildId(entity.Entity.Id).Any())
         {
             //e.Cancel = true;
             e.CancelOperation(new Umbraco.Core.Events.EventMessage("UWS", "Cannot be deleted because the content is used elsewhere in the site. Please check the related content section for more information.", Umbraco.Core.Events.EventMessageType.Error));
             //e.Messages.Add(new Umbraco.Core.Events.EventMessage("UWS", "Cannot be deleted because the content is used elsewhere in the site. Please check the related content section for more information.", Umbraco.Core.Events.EventMessageType.Success));
             break;
         }
     }
 }
示例#3
0
        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
            });
        }