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 })); }
protected override DriverResult Editor(ContainablePart part, IUpdateModel updater, dynamic shapeHelper) { return(ContentShape( "Parts_Containable_Edit", () => { var settings = part.TypePartDefinition.Settings.GetModel <ContainableTypePartSettings>(); var commonPart = part.As <CommonPart>(); var model = new ContainableViewModel { ShowContainerPicker = settings.ShowContainerPicker, ShowPositionEditor = settings.ShowPositionEditor, Position = part.Position }; if (commonPart != null && commonPart.Container != null) { model.ContainerId = commonPart.Container.Id; } if (part.Id == 0 && commonPart != null && commonPart.Container != null) { part.Position = _containerService.GetFirstPosition(commonPart.Container.Id) + 1; } if (updater != null) { var oldContainerId = model.ContainerId; updater.TryUpdateModel(model, "Containable", null, new[] { "ShowContainerPicker", "ShowPositionEditor" }); if (oldContainerId != model.ContainerId) { if (commonPart != null) { var containerItem = _contentManager.Get(model.ContainerId, VersionOptions.Latest); commonPart.Container = containerItem; } } part.Position = model.Position; } var containers = _contentManager .Query <ContainerPart, ContainerPartRecord>(VersionOptions.Latest) .List() .Where(container => container.ItemContentTypes.Any(type => type.Name == part.TypeDefinition.Name)); var listItems = new[] { new SelectListItem { Text = T("(None)").Text, Value = "0" } } .Concat(containers.Select(x => new SelectListItem { Value = Convert.ToString(x.Id), Text = x.ContentItem.TypeDefinition.DisplayName + ": " + _contentManager.GetItemMetadata(x.ContentItem).DisplayText, Selected = x.Id == model.ContainerId, })) .ToList(); model.AvailableContainers = new SelectList(listItems, "Value", "Text", model.ContainerId); model.Position = part.Position; return shapeHelper.EditorTemplate(TemplateName: "Containable", Model: model, Prefix: "Containable"); })); }