Example #1
0
        public ActionResult Create([ModelBinder(typeof(TypeConverterModelBinder))] ContentPath path, string container, string type, FormCollection formValues)
        {
            var contentInfo = CreateNewContent(path, container, type);

            return(UpdateContent(
                       contentInfo,
                       s => path.Append(s),
                       newPath => View("Celes.Created", newPath)
                       ));
        }
Example #2
0
        private void RebuildPathCache(IEnumerable <IContent> contents, ContentPath parentPath, ContentPathCacheEntry parentEntry)
        {
            var cachedContents = contents.ToList();

            if (cachedContents.Count == 0)
            {
                return;
            }

            foreach (var item in cachedContents.Select((c, i) => new { Content = c, Index = i }))
            {
                var content = item.Content;

                var path = parentPath != null
                                        ? parentPath.Append(content.Alias)
                                        : ContentPath.Root;

                var actualContentType = ObjectContext.GetObjectType(content.GetType());

                var collectionProperties = _collectionPropertiesByType.GetOrAdd(actualContentType, t => t
                                                                                .GetProperties(BindingFlags.Public | BindingFlags.Instance)
                                                                                .Select(p => new { Property = p, CollectionType = p.PropertyType.GetImplementationOf(typeof(IEnumerable <>)) })
                                                                                .Where(p => p.CollectionType != null)
                                                                                .Select(p => new { Property = p.Property, ChildType = p.CollectionType.GetGenericArguments().First() })
                                                                                .Where(p => typeof(IContent).IsAssignableFrom(p.ChildType))
                                                                                .Select(p => p.Property)
                                                                                .ToList());

                var cacheEntry = CreateCacheEntry(content.Id, actualContentType, path, parentEntry, item.Index);

                foreach (var collectionProperty in collectionProperties)
                {
                    var children = (IEnumerable <IContent>)collectionProperty.GetValue(content, null);
                    RebuildPathCache(children, path, cacheEntry);
                }
            }
        }
        private void RebuildPathCache(IEnumerable<IContent> contents, ContentPath parentPath, ContentPathCacheEntry parentEntry)
        {
            var cachedContents = contents.ToList();
            if (cachedContents.Count == 0)
            {
                return;
            }

            foreach (var item in cachedContents.Select((c, i) => new { Content = c, Index = i }))
            {
                var content = item.Content;

                var path = parentPath != null
                    ? parentPath.Append(content.Alias)
                    : ContentPath.Root;

                var actualContentType = ObjectContext.GetObjectType(content.GetType());

                var collectionProperties = _collectionPropertiesByType.GetOrAdd(actualContentType, t => t
                    .GetProperties(BindingFlags.Public | BindingFlags.Instance)
                    .Select(p => new { Property = p, CollectionType = p.PropertyType.GetImplementationOf(typeof(IEnumerable<>)) })
                    .Where(p => p.CollectionType != null)
                    .Select(p => new { Property = p.Property, ChildType = p.CollectionType.GetGenericArguments().First() })
                    .Where(p => typeof(IContent).IsAssignableFrom(p.ChildType))
                    .Select(p => p.Property)
                    .ToList());

                var cacheEntry = CreateCacheEntry(content.Id, actualContentType, path, parentEntry, item.Index);

                foreach (var collectionProperty in collectionProperties)
                {
                    var children = (IEnumerable<IContent>)collectionProperty.GetValue(content, null);
                    RebuildPathCache(children, path, cacheEntry);
                }
            }
        }