Ejemplo n.º 1
0
        public override bool UpdateItem(ContentItem item, Control editor)
        {
            bool           updated    = false;
            ItemEditorList listEditor = (ItemEditorList)editor;

            for (int i = 0; i < listEditor.ItemEditors.Count; i++)
            {
                if (listEditor.DeletedIndexes.Contains(i))
                {
                    var deletedChild = listEditor.ItemEditors[i].CurrentItem;
                    if (deletedChild.ID == 0)
                    {
                        deletedChild.AddTo(null);
                    }
                    else
                    {
                        Engine.Persister.Delete(deletedChild);
                    }
                }
                else
                {
                    ItemEditor childEditor  = listEditor.ItemEditors[i];
                    ItemEditor parentEditor = ItemUtility.FindInParents <ItemEditor>(editor.Parent);
                    if (parentEditor != null)
                    {
                        var subContext = parentEditor.BinderContext.CreateNestedContext(childEditor, childEditor.CurrentItem, childEditor.GetDefinition());
                        if (subContext.Binder.UpdateObject(subContext))
                        {
                            updated = true;
                        }
                    }
                    else
                    {
                        IItemEditor fallbackEditor = ItemUtility.FindInParents <IItemEditor>(editor.Parent);
                        if (fallbackEditor != null)
                        {
                            fallbackEditor.Saved += delegate { childEditor.Save(); };
                        }
                    }
                }
            }
            return(updated || listEditor.DeletedIndexes.Count > 0 || listEditor.AddedTypes.Count > 0);
        }