Class ItemService
- Namespace
- Dynamicweb.Content
- Assembly
- Dynamicweb.dll
Provides methods for querying and persisting items.
public class ItemService : IItemService, IRecyclable<ItemEntry>
- Inheritance
-
ItemService
- Implements
- Inherited Members
Examples
using System;
using System.Collections.Generic;
using Dynamicweb.Content;
using Dynamicweb.Content.Items;
namespace Dynamicweb.Examples.Items
{
public class ItemServiceSample
{
public static IList<ItemEntry> CreateItems()
{
var service = Dynamicweb.Content.Services.Items;
var news = new ExampleNewsItem
{
Title = "Example of new related item",
NewsDate = DateTime.Now
};
service.SaveItem(news);
var newsCopy = (Item)news.Copy();
newsCopy["Title"] = "Example of item copy";
service.SaveItem(newsCopy);
var genericCopy = news.Copy<ExampleNewsItem>();
genericCopy.Title = "Example of generic copy";
service.SaveItem(genericCopy);
return new List<ItemEntry> { news, newsCopy, genericCopy };
}
ItemEntry CopyItem(string itemType, string itemId)
{
var service = Dynamicweb.Content.Services.Items;
var item = service.GetItem(itemType, itemId);
return service.SaveItem(item.Copy());
}
ItemEntry CopyPageItem(Page page)
{
var service = Dynamicweb.Content.Services.Items;
var item = service.CopyPageItem(page);
if(item != null)
{
item = service.SaveItem(item);
}
return item;
}
ItemEntry CopyParagraphItem(Paragraph paragraph)
{
var service = Dynamicweb.Content.Services.Items;
var item = service.CopyParagraphItem(paragraph);
if (item != null)
{
item = service.SaveItem(item);
}
return item;
}
}
}
Methods
CopyItem(string, string, int, ItemContext)
Creates a copy of the Item with the specified item id and item type
public ItemEntry CopyItem(string itemType, string itemId, int sort, ItemContext context)
Parameters
itemTypestring- Type of the item.
itemIdstring- The item identifier.
sortint- The sort index of the item.
contextItemContext- The item context.
Returns
- ItemEntry
- A copy of the item with the specified id
CopyPageItem(Page)
Creates a copy of the Item with the specified item id and item type
public ItemEntry CopyPageItem(Page page)
Parameters
pagePage- The page from which to make a copy of it's associated Item
Returns
- ItemEntry
- A copy of the item associated with the specified page, of any
CopyParagraphItem(Paragraph)
Creates a copy of the Item with the specified item id and item type
public ItemEntry CopyParagraphItem(Paragraph paragraph)
Parameters
paragraphParagraph- The paragraph from which to make a copy of it's associated Item
Returns
- ItemEntry
- A copy of the item associated with the specified paragraph, of any
CustomizeItemType(ItemType)
Customizes the item type. It creates the full copy of item type and its templates, and replaces the usages of item type by custom item type.
public ItemType CustomizeItemType(ItemType itemType)
Parameters
itemTypeItemType- The item type to customize. The item type customization is only available for Websites, Pages, and Paragraphs.
Returns
DeleteItemTypes(IEnumerable<string>, string)
public void DeleteItemTypes(IEnumerable<string> itemSystemNames, string deleteMode)
Parameters
itemSystemNamesIEnumerable<string>deleteModestring
GetItem(string, string)
Gets the item.
public Item GetItem(string itemType, string itemId)
Parameters
Returns
- Item
- ItemEntry.
GetItem(string, string, bool)
Gets the item.
public Item GetItem(string itemType, string itemId, bool draft)
Parameters
Returns
- Item
- ItemEntry.
GetItem(string, string, bool, DateTime)
Gets the item.
public Item GetItem(string itemType, string itemId, bool draft, DateTime previewDate)
Parameters
itemTypestring- Type of the item.
itemIdstring- The item identifier.
draftbool- Look for draft
previewDateDateTime- Date of preview
Returns
- Item
- ItemEntry.
GetItemById<T>(string)
Gets the item.
public T GetItemById<T>(string itemId) where T : ItemEntry, new()
Parameters
itemIdstring- The item identifier.
Returns
- T
- ItemEntry.
Type Parameters
T
GetItemByPageId(int, bool)
Gets page item by the given page Id.
public Item GetItemByPageId(int pageId, bool draft)
Parameters
Returns
- Item
- Item with the given Id.
GetItemByPageId(int, bool, DateTime)
Gets page item by the given page Id.
public Item GetItemByPageId(int pageId, bool draft, DateTime previewDate)
Parameters
pageIdint- Page Id.
draftbool- Is item in a draft mode
previewDateDateTime- Date to preview the content from
Returns
- Item
- Item with the given Id.
GetTitle(Item)
Returns page title.
public string GetTitle(Item item)
Parameters
itemItem- The item.
Returns
- string
- Value to use as page title.
IsItemTypeCustomizable(ItemType)
Determines if the item type is customizable.
public bool IsItemTypeCustomizable(ItemType itemType)
Parameters
itemTypeItemType- The item type.
Returns
MoveToBin(ItemEntry)
Moves the specified item, linked items and items from related list to the bin
public Guid MoveToBin(ItemEntry obj)
Parameters
objItemEntry- The item entry to move to the bin
Returns
MoveToExistingBin(ItemEntry, Guid)
Moves the specified item, linked items and items from related list to an existing bin having the specified UnitID.
If the bin is a non existing bin, the item will be assigned as the Primary Item of the RecycleBin, otherwise it will just be a part of the items in the bin
public void MoveToExistingBin(ItemEntry obj, Guid unitId)
Parameters
Restore(object)
Restores the item entry and related objects.
public void Restore(object id)
Parameters
idobject- The id of the item entry to restore
RestoreItem(ItemStoreContainer)
Restores the item entry and related objects.
public void RestoreItem(ItemStoreContainer store)
Parameters
storeItemStoreContainer- The container to store items and related objects
Exceptions
- InvalidOperationException
- Thrown when there is attempt to restore item having non-existing itemtype.
RestoreItem(ItemStoreContainer, bool)
Restores the item entry and related objects with new id.
public void RestoreItem(ItemStoreContainer store, bool generateNewId)
Parameters
storeItemStoreContainer- The container to store items and related objects
generateNewIdbool
SaveItem(ItemEntry)
Saves the new item to persistence
public ItemEntry SaveItem(ItemEntry item)
Parameters
itemItemEntry- The item to save to persistence
Returns
- ItemEntry
- The newly save item
SaveItemType(ItemType)
Saves the item type
public void SaveItemType(ItemType itemType)
Parameters
itemTypeItemType- The item type to save
SynchronizeListField(Item, Item, string)
Synchronize list field on language item by master
public void SynchronizeListField(Item masterItem, Item languageItem, string fieldName)
Parameters
masterItemItem- The master item
languageItemItem- The language item
fieldNamestring- The field name with list to synchronize
UpdateItemSortIndex(string, string, int)
Updates the item sort index
public void UpdateItemSortIndex(string itemType, string itemId, int sortIndex)
Parameters
itemTypestring- The itemtype of the item to update sort index
itemIdstring- The id of the item to update sort index
sortIndexint- The index used for sort index
UpdateItemTitle(ItemType, Item, string)
Updates item field used for page title.
public void UpdateItemTitle(ItemType itemMetaType, Item item, string title)
Parameters
UpdateItemTitle(string, string, string)
Updates item field used for page title.
public void UpdateItemTitle(string itemType, string itemId, string title)