Various updates to MyGeneration

Moved ItemInsert code to ItemInsertExt.cs
This commit is contained in:
Rich
2009-04-22 13:04:26 +00:00
parent 518c79216a
commit 7f0eb11f47
8 changed files with 871 additions and 601 deletions

View File

@@ -1311,147 +1311,6 @@ namespace VEPROMS.CSLA.Library
{
_MyContent = new ContentInfo(dr, true);
}
#region Insert New Items
public ItemInfo InsertSiblingBefore(string text)
{
return InsertSiblingBefore(text, null);
}
public ItemInfo InsertSiblingBefore(string text, string number)
{
ItemInfo prevItemInfo = MyPrevious;
ItemInfo newItemInfo = null;
PartInfoList partInfoList = null;
if(MyParent != null && MyParent.MyContent != null)
{
MyParent.MyContent.RefreshContentParts();
partInfoList = MyParent.MyContent.ContentParts;
}
using (Item prevItem = prevItemInfo == null ? null : prevItemInfo.Get()) // Get the previous Item
{
using (Item newItem = Item.MakeItem(prevItem, Content.MakeContent(number, "", MyContent.Type, null, null))) // Create the new Item
{
using (Item thisItem = Get()) // Get the next item in the list
{
thisItem.MyPrevious = newItem; // Point to the new item
thisItem.Save(); // Save Changes
if (prevItem == null)
{
PartInfo partInfo = partInfoList.Find(this);
using (Part part = partInfo.Get())
{
part.MyItem = newItem;
part.Save();
}
}
}
// ToDo: Need change PartInfo in PartInfoList
newItemInfo = ItemInfo.Get(newItem.ItemID);
newItemInfo.ResetOrdinal();
}
}
return newItemInfo;
}
public ItemInfo InsertSiblingAfter(string text)
{
return InsertSiblingAfter(text, null);
}
public ItemInfo InsertSiblingAfter(string text, string number)
{
return InsertSiblingAfter(text, number, MyContent.Type);
}
public ItemInfo InsertSiblingAfter(string text, string number, int? type)
{
ItemInfo nextItemInfo = (NextItemCount > 0) ? NextItems[0] : null;
ItemInfo newItemInfo = null;
using (Item thisItem = Get()) // Get the Current Item
{
using (Item newItem = Item.MakeItem(thisItem, Content.MakeContent(number, text, type, null, null))) // Create the new Item
{
if (nextItemInfo != null) // Simple case, adding to end of list:
using (Item nextItem = nextItemInfo.Get()) // Get the next item in the list
{
nextItem.MyPrevious = newItem; // Point to the new item
nextItem.Save(); // Save Changes
}
// ToDo: Need change PartInfo in PartInfoList
newItemInfo = ItemInfo.Get(newItem.ItemID);
newItemInfo.ResetOrdinal();
}
}
return newItemInfo;
}
public ItemInfo InsertChild(E_FromType fromType,int type,string text)
{
return InsertChild(fromType,type,text, null);
}
public ItemInfo InsertChild(E_FromType fromType,int type, string text, string number)
{
ItemInfo newItemInfo = null;
using (Item thisItem = Get()) // Get the Current Item
{
using (Item newItem = Item.MakeItem(null, Content.MakeContent(number, text, type, null, null))) // Create the new Item
{
PartInfo partInfo = MyContent.ContentParts == null ? null : MyContent.ContentParts.Find(fromType);
if (partInfo != null)
{
//this could be equivalent to adding a sibling with a specific type
using (Part part = partInfo.Get())
{
part.MyItem.MyPrevious = newItem;
part.MyItem.Save();
part.MyItem = newItem;
part.Save();
}
}
else
{
// This means that a part needs to be added to point to the new item
//using (Part part = Part.MakePart(thisItem.MyContent, ))
//{ ;}
thisItem.MyContent.ContentParts.Add((int)fromType, newItem);
thisItem.Save();
}
newItemInfo = ItemInfo.Get(newItem.ItemID);
}
}
ResetParts();
return newItemInfo;
}
public ItemInfo NextItem
{
get
{
if (NextItemCount > 0 && NextItems.Count > 0)
return NextItems[0];
return null;
}
}
private static void ResetOrdinal(int itemID)
{
bool first = true;
ConvertListToDictionary();
string key = itemID.ToString();
if (_CacheByPrimaryKey.ContainsKey(key))
{
foreach (ItemInfo itm in _CacheByPrimaryKey[key])
{
itm._Ordinal = null;
//Console.WriteLine("Ordinal {0},{1}",key,itm.MyPrevious == null ? 0 : itm.MyPrevious._Ordinal);
if (first && itm.NextItem != null)
{
ResetOrdinal(itm.NextItem.ItemID);
first = false;
}
}
}
}
private void ResetOrdinal()
{
//_Ordinal = null;
//Console.WriteLine("Ordinal {0},{1}",ItemID,MyPrevious == null ? 0 : MyPrevious.Ordinal);
ResetOrdinal(ItemID);
}
#endregion
}
#endregion ItemInfo
#region ItemInfoList