Ejemplo n.º 1
0
        /// <summary>
        /// Returns the ViewResult for use in the Move/Copy dialogs
        /// </summary>
        /// <returns></returns>
        protected ActionResult MoveCopyView(HiveId id, MoveModel model)
        {

            using (var uow = Hive.Create<IContentStore>())
            {
                var contentData = uow.Repositories.Get<TypedEntity>(id);
                if (contentData == null)
                    throw new ArgumentException(string.Format("No content found for id: {0} on action Move/Copy", id));

                //TODO: need to filter the start id based on the user's start node id, or just put that funcionality into the url helper

                //get the tree url for use in the copy/move dialog
                var treeUrl = Url.GetTreeUrl(new HiveId(_treeId), _treeId,
                                             new
                                                 {
                                                     //specify that the tree is in dialog mode
                                                     DialogMode = true,
                                                     //specify the onClick JS method handler for the node
                                                     OnNodeClick = "Umbraco.Editors.MoveCopyDialog.getInstance().nodeClickHandler"
                                                 });

                var contentItem = BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map<TypedEntity, ContentEditorModel>(contentData);

                model.SelectedItemId = contentItem.Id;
                model.SelectedItemName = contentItem.Name;
                model.TreeRenderModel = new TreeRenderModel(treeUrl, "moveCopyTree")
                    {
                        ShowContextMenu = false
                    };
                return View(model);
            }
        }
Ejemplo n.º 2
0
        //[UmbracoAuthorize(Permissions = new[] { FixedPermissionIds.Move })]  
        public virtual JsonResult MoveForm(MoveModel model)
        {
            if (!TryValidateModel(model))
            {
                return ModelState.ToJsonErrors();
            }

            return ProcessMoveCopy(model.SelectedItemId, model.ToId, (selectedEntity, toEntity, uow) =>
                {
                    var previousParents = uow.Repositories.GetParentRelations(selectedEntity, FixedRelationTypes.DefaultRelationType);
                    if (!previousParents.Any())
                        throw new InvalidOperationException(
                            "Could not find any parents for entity '{0}' with id {1}".InvariantFormat(
                                model.SelectedItemName, model.SelectedItemId));

                    // TODO: (APN) At the moment the MoveModel does not provide the single parent from which we're moving, 
                    // so we've had to load all parents. We need to change one, and remove the rest.
                    var toChange = previousParents.FirstOrDefault();
                    var rest = previousParents.Skip(1);
                    uow.Repositories.ChangeRelation(toChange, toEntity.Id, toChange.DestinationId);
                    rest.ForEach(x => uow.Repositories.RemoveRelation(x));

                    uow.Complete();

                    return new Tuple<string, EntityPathCollection, string>(
                        "Move.Success.Message".Localize(this, new
                            {
                                FromName = selectedEntity.GetAttributeValueAsString(NodeNameAttributeDefinition.AliasValue, "Name"),
                                ToName = toEntity.GetAttributeValueAsString(NodeNameAttributeDefinition.AliasValue, "Name")
                            }, encode: false),
                        uow.Repositories.GetEntityPaths<TypedEntity>(toChange.DestinationId, FixedRelationTypes.DefaultRelationType),
                        "move");

                });
        }