本文整理汇总了C#中ContentItem.AddTo方法的典型用法代码示例。如果您正苦于以下问题:C# ContentItem.AddTo方法的具体用法?C# ContentItem.AddTo怎么用?C# ContentItem.AddTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ContentItem
的用法示例。
在下文中一共展示了ContentItem.AddTo方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MoveTo
public void MoveTo(ContentItem item, ContentItem parent)
{
if (item.Parent == parent)
{
// move it last
item.AddTo(null);
item.AddTo(parent);
}
else if (item.Parent == null || !parent.Children.Contains(item))
item.AddTo(parent);
UpdateSortOrderAndSave(parent);
}
示例2: MoveTo
public void MoveTo(ContentItem item, NodePosition position, ContentItem relativeTo)
{
if (relativeTo == null) throw new ArgumentNullException("item");
if (relativeTo == null) throw new ArgumentNullException("relativeTo");
if (relativeTo.Parent == null) throw new ArgumentException("The supplied item '" + relativeTo + "' has no parent to add to.", "relativeTo");
if (item.Parent == null
|| item.Parent != relativeTo.Parent
|| !item.Parent.Children.Contains(item))
item.AddTo(relativeTo.Parent);
IList<ContentItem> siblings = item.Parent.Children;
int itemIndex = siblings.IndexOf(item);
int relativeToIndex = siblings.IndexOf(relativeTo);
if(itemIndex < 0)
{
if(position == NodePosition.Before)
siblings.Insert(relativeToIndex, item);
else
siblings.Insert(relativeToIndex + 1, item);
}
else if(itemIndex < relativeToIndex && position == NodePosition.Before)
MoveTo(item, relativeToIndex - 1);
else if (itemIndex > relativeToIndex && position == NodePosition.After)
MoveTo(item, relativeToIndex + 1);
else
MoveTo(item, relativeToIndex);
}
示例3: MoveTo
public void MoveTo(ContentItem item, ContentItem parent)
{
if (item.Parent == parent)
{
// move it last
item.AddTo(null);
item.AddTo(parent);
}
else if (item.Parent == null || !parent.Children.Contains(item))
item.AddTo(parent);
using (var tx = persister.Repository.BeginTransaction())
{
foreach (ContentItem updatedItem in Utility.UpdateSortOrder(parent.Children))
{
persister.Repository.SaveOrUpdate(updatedItem);
}
tx.Commit();
}
}
示例4: AddTemplate
public void AddTemplate(ContentItem templateItem)
{
TemplateContainer templates = container.GetOrCreateBelowRoot((c) =>
{
c.Title = "Templates";
c.Name = "Templates";
c.Visible = false;
c.SortOrder = int.MaxValue - 1001000;
});
templateItem.Name = null;
templateItem.AddTo(templates);
persister.Save(templateItem);
}
示例5: InsertChildBefore
public static void InsertChildBefore(this ContentItem parent, ContentItem child, int beforeSortOrder)
{
bool wasAdded = false;
for (int i = 0; i < parent.Children.Count; i++)
{
var sibling = parent.Children[i];
if (sibling.SortOrder >= beforeSortOrder)
{
parent.Children.Insert(i, child);
Utility.UpdateSortOrder(parent.Children);
wasAdded = true;
break;
}
}
if (!wasAdded)
{
child.AddTo(parent);
Utility.UpdateSortOrder(parent.Children);
}
}
示例6: Save
public override void Save(ContentItem item)
{
using (var tx = repository.BeginTransaction())
{
// update updated date unless it's a version being saved
if (!item.VersionOf.HasValue)
item.Updated = Utility.CurrentTime();
// empty string names not allowed, null is replaced with item id
if (string.IsNullOrEmpty(item.Name))
item.Name = null;
item.AddTo(item.Parent);
// make sure the ordering is the same next time these siblings are loaded
var unsavedItems = item.Parent.EnsureChildrenSortOrder();
foreach (var itemToSave in unsavedItems.Union(new [] { item }))
{
repository.SaveOrUpdate(itemToSave);
}
// ensure a name, fallback to id
if (string.IsNullOrEmpty(item.Name))
{
item.Name = item.ID.ToString();
repository.SaveOrUpdate(item);
}
tx.Commit();
}
}
示例7: Move
public override ContentItem Move(ContentItem source, ContentItem destination)
{
using (var tx = repository.BeginTransaction())
{
Trace.TraceInformation("ContentPersister.MoveAction " + source + " to " + destination);
source.AddTo(destination);
foreach (var descendant in UpdateAncestralTrailRecursive(source, destination))
{
repository.SaveOrUpdate(descendant);
}
Save(source);
tx.Commit();
}
return source;
}
示例8: DeleteRecursive
private void DeleteRecursive(ContentItem itemToDelete)
{
DeletePreviousVersions(itemToDelete);
try
{
Trace.Indent();
foreach (ContentItem child in itemToDelete.Children.ToList())
DeleteRecursive(child);
}
finally
{
Trace.Unindent();
}
itemToDelete.AddTo(null);
Trace.TraceInformation("DatabaseSource.DeleteRecursive " + itemToDelete);
repository.Delete(itemToDelete);
}
示例9: HandleParentRelation
protected virtual void HandleParentRelation(ContentItem item, string parent, ReadingJournal journal)
{
if (!string.IsNullOrEmpty(parent))
{
int parentID = int.Parse(parent);
ContentItem parentItem = journal.Find(parentID);
item.AddTo(parentItem);
}
}
示例10: HandleParentRelation
protected virtual void HandleParentRelation(ContentItem item, string parent, string parentVersionKey, ReadingJournal journal)
{
int parentID = 0;
if (int.TryParse(parent, out parentID) && parentID != 0)
{
ContentItem parentItem = journal.Find(parentID);
if (parentItem != null)
item.AddTo(parentItem);
else
journal.Register(parentID, (laterParent) => item.AddTo(laterParent), isChild: true);
}
if (!string.IsNullOrEmpty(parentVersionKey))
{
ContentItem parentItem = journal.Find(parentVersionKey);
if (parentItem != null)
item.AddTo(parentItem);
else
journal.Register(parentVersionKey, (laterParent) => item.AddTo(laterParent), isChild: true);
}
}
示例11: DeleteRecursive
private void DeleteRecursive(ContentItem itemToDelete)
{
using (logger.Indent())
{
foreach (ContentItem child in itemToDelete.Children.ToList())
DeleteRecursive(child);
}
itemToDelete.AddTo(null);
logger.InfoFormat("Deleting {0}", itemToDelete);
repository.Delete(itemToDelete);
}
示例12: RegisterParentRelation
public void RegisterParentRelation(int parentID, ContentItem item)
{
Register(parentID, (laterParent) => item.AddTo(laterParent), isChild: true, relationType: "parent", referencingItem: item);
}
示例13: MoveTo
public void MoveTo(ContentItem item, NodePosition position, ContentItem relativeTo)
{
if (relativeTo == null) throw new ArgumentNullException("item");
if (relativeTo == null) throw new ArgumentNullException("relativeTo");
if (relativeTo.Parent == null) throw new ArgumentException("The supplied item '" + relativeTo + "' has no parent to add to.", "relativeTo");
using (var tx = persister.Repository.BeginTransaction())
{
if (item.Parent == null
|| item.Parent != relativeTo.Parent
|| !item.Parent.Children.Contains(item))
{
item.AddTo(relativeTo.Parent);
if (ItemMoved != null)
ItemMoved.Invoke(this, new DestinationEventArgs(item, relativeTo.Parent));
//foreach (ContentItem updatedItem in item.UpdateAncestralTrailRecursive(relativeTo.Parent))
//{
// persister.Repository.SaveOrUpdate(updatedItem);
//}
}
IList<ContentItem> siblings = item.Parent.Children;
int itemIndex = siblings.IndexOf(item);
int relativeToIndex = siblings.IndexOf(relativeTo);
if(itemIndex < 0)
{
if(position == NodePosition.Before)
siblings.Insert(relativeToIndex, item);
else
siblings.Insert(relativeToIndex + 1, item);
}
else if(itemIndex < relativeToIndex && position == NodePosition.Before)
MoveTo(item, relativeToIndex - 1);
else if (itemIndex > relativeToIndex && position == NodePosition.After)
MoveTo(item, relativeToIndex + 1);
else
MoveTo(item, relativeToIndex);
tx.Commit();
}
}
示例14: AddTemplate
public void AddTemplate(ContentItem templateItem)
{
TemplateContainer templates = container.GetOrCreateBelowRoot((c) =>
{
c.Title = "Templates";
c.Name = "Templates";
c.Visible = false;
c.SortOrder = int.MaxValue - 1001000;
});
templateItem.Name = null;
templateItem.AddTo(templates);
using (var tx = repository.BeginTransaction())
{
repository.SaveOrUpdate(templateItem);
tx.Commit();
}
}