示例#1
0
        public ActionResult Insert(int containerId, int itemId, PagerParameters pagerParameters)
        {
            var             container             = _containerService.Get(containerId, VersionOptions.Latest);
            var             item                  = _contentManager.Get(itemId, VersionOptions.Latest, QueryHints.Empty.ExpandParts <CommonPart, ContainablePart>());
            var             commonPart            = item.As <CommonPart>();
            var             previousItemContainer = commonPart.Container;
            var             itemMetadata          = _contentManager.GetItemMetadata(item);
            var             containerMetadata     = _contentManager.GetItemMetadata(container);
            var             position              = _containerService.GetFirstPosition(containerId) + 1;
            LocalizedString message;

            if (previousItemContainer == null)
            {
                message = T("{0} was moved to <a href=\"{1}\">{2}</a>", itemMetadata.DisplayText, Url.RouteUrl(containerMetadata.AdminRouteValues), containerMetadata.DisplayText);
            }
            else if (previousItemContainer.Id != containerId)
            {
                var previousItemContainerMetadata = _contentManager.GetItemMetadata(commonPart.Container);
                message = T("{0} was moved from <a href=\"{3}\">{4}</a> to <a href=\"{1}\">{2}</a>",
                            itemMetadata.DisplayText,
                            Url.RouteUrl(containerMetadata.AdminRouteValues),
                            containerMetadata.DisplayText,
                            Url.RouteUrl(previousItemContainerMetadata.AdminRouteValues),
                            previousItemContainerMetadata.DisplayText);
            }
            else
            {
                message = T("{0} is already part of this list and was moved to the top.", itemMetadata.DisplayText);
            }

            _containerService.MoveItem(item.As <ContainablePart>(), container, position);
            _services.Notifier.Information(message);
            return(RedirectToAction("List", new { containerId, page = pagerParameters.Page, pageSize = pagerParameters.PageSize }));
        }