Esempio n. 1
0
        private string MoveItem(NameValueCollection request)
        {
            var         path = PartsExtensions.EnsureDraft(versions, versionRepository, navigator, request);
            ContentItem item = path.CurrentItem;
            ContentItem page = path.CurrentPage;

            item.ZoneName = request["zone"];

            var         beforeItem = PartsExtensions.GetBeforeItem(navigator, request, page);
            ContentItem parent;

            if (beforeItem != null)
            {
                parent = beforeItem.Parent;
                int newIndex = parent.Children.IndexOf(beforeItem);
                ValidateLocation(item, parent);
                Utility.Insert(item, parent, newIndex);
            }
            else
            {
                parent = PartsExtensions.GetBelowItem(navigator, request, page);
                ValidateLocation(item, parent);
                Utility.Insert(item, parent, parent.Children.Count);
            }

            Utility.UpdateSortOrder(parent.Children);
            versionRepository.Save(page);

            return(page.Url.ToUrl().SetQueryParameter("edit", "drag"));
        }
        // find the target item and index
        protected ContentItem GetParentAndIndex(NameValueCollection request, ContentItem page, out int newIndex)
        {
            var         beforeItem = PartsExtensions.GetBeforeItem(navigator, request, page);
            ContentItem parent;

            if (beforeItem != null)
            {
                parent   = beforeItem.Parent;
                newIndex = parent.Children.IndexOf(beforeItem);
            }
            else
            {
                parent   = PartsExtensions.GetBelowItem(navigator, request, page);
                newIndex = parent == null ? 0 : parent.Children.Count;
            }
            return(parent);
        }
Esempio n. 3
0
        private string CopyItem(NameValueCollection request)
        {
            var         path = PartsExtensions.EnsureDraft(versions, versionRepository, navigator, request);
            ContentItem item = path.CurrentItem;
            ContentItem page = path.CurrentPage;

            item          = item.Clone(true);
            item.Name     = null;
            item.ZoneName = request["zone"];
            foreach (var child in Find.EnumerateChildren(item, true, false))
            {
                child.SetVersionKey(Guid.NewGuid().ToString());
            }

            var         beforeItem = PartsExtensions.GetBeforeItem(navigator, request, page);
            ContentItem parent;

            if (beforeItem != null)
            {
                parent = beforeItem.Parent;
                int newIndex = parent.Children.IndexOf(beforeItem);
                ValidateLocation(item, parent);
                Utility.Insert(item, parent, newIndex);
            }
            else
            {
                parent = PartsExtensions.GetBelowItem(navigator, request, page);
                ValidateLocation(item, parent);
                Utility.Insert(item, parent, parent.Children.Count);
            }

            Utility.UpdateSortOrder(parent.Children);
            versionRepository.Save(page);

            return(page.Url.ToUrl().SetQueryParameter("edit", "drag"));
        }