Пример #1
0
        private static void ProcessRelationship(IContentService contentService, IContent block, IContent content,
                                                IRelationType bentoBlocksRelationType, string blockDoctypeCompositionAlias)
        {
            //check that the control is a block i.e. it's composed of the block type composition doctype
            //IContent block = contentService.GetById(controlValueId);
            if (block == null)
            {
                return;
            }

            IContentTypeComposition contentTypeOf = ContentTypeService.GetContentTypeOf(block);

            if (contentTypeOf.ContentTypeComposition.FirstOrDefault(x => x.Alias == blockDoctypeCompositionAlias) == null)
            {
                return;
            }

            bool areRelated = RelationService.AreRelated(content, block, RelationTypes.BentoItemsAlias);

            if (areRelated)
            {
                return;
            }

            Relation relation = new Relation(content.Id, block.Id, bentoBlocksRelationType);

            //possibly record additional info on the comment field e.g. who created the relationship (so the editor of the parent)
            //var user = UserService.GetByUsername(HttpContext.Current.User.Identity.Name);
            //relation.Comment = user.Name;
            RelationService.Save(relation);
        }
Пример #2
0
        private bool checkRelationship(int parentNode, int childNode)
        {
            /*
             *Checking whether parent and child items are proper content/media items doesn't work for media. 
             *MediaServie hits the Examine Indexes first and if the indexes does not exist, hits the database next.
             *Any new media item that gets created takes a while to appear in the indexes which makes MediaService not return that 
             item in the Descendants list. This makes the "check if the parentNode and childNode are actual content/media items in the website"
             below return the wrong value as if the media is not a proper media item.
             *The logic needs to be removed and it is okay to just check the existence of the relationship directly.
             */

        

            Current.Logger.Info(this.GetType(), string.Format("Checking if parent: {0} and child: {1} are related", parentNode, childNode));

            var result =  relationService.AreRelated(parentNode, childNode);

            if(result)
                Current.Logger.Info(this.GetType(), string.Format("Parent: {0} and child: {1} are related", parentNode, childNode));
            else
                Current.Logger.Info(this.GetType(), string.Format("Parent: {0} and child: {1} are not related", parentNode, childNode));


            return result;
        }