Class ItemService
- Namespace
- Dynamicweb.Content
- Assembly
- Dynamicweb.dll
Provides methods for querying and persisting items.
public class ItemService
- Inheritance
-
ItemService
- 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
itemType
stringType of the item.
itemId
stringThe item identifier.
sort
intThe sort index of the item.
context
ItemContextThe 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
page
PageThe 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
paragraph
ParagraphThe 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
itemType
ItemTypeThe 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
itemSystemNames
IEnumerable<string>deleteMode
string
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
itemType
stringType of the item.
itemId
stringThe item identifier.
draft
boolLook for draft
previewDate
DateTimeDate of preview
Returns
- Item
ItemEntry.
GetItemById<T>(string)
public T GetItemById<T>(string itemId) where T : ItemEntry, new()
Parameters
itemId
string
Returns
- T
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
pageId
intPage Id.
draft
boolIs item in a draft mode
previewDate
DateTimeDate to preview the content from
Returns
- Item
Item with the given Id.
GetTitle(Item)
Returns page title.
public string GetTitle(Item item)
Parameters
item
ItemThe item.
Returns
- string
Value to use as page title.
IsItemTypeCustomizable(ItemType)
Determines if the item type is customizable.
public bool IsItemTypeCustomizable(ItemType itemType)
Parameters
itemType
ItemTypeThe item type.
Returns
RestoreItem(ItemStoreContainer)
Restores the item entry and related objects.
public void RestoreItem(ItemStoreContainer store)
Parameters
store
ItemStoreContainerThe 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
store
ItemStoreContainerThe container to store items and related objects
generateNewId
bool
SaveItem(ItemEntry)
Saves the new item to persistence
public ItemEntry SaveItem(ItemEntry item)
Parameters
item
ItemEntryThe item to save to persistence
Returns
- ItemEntry
The newly save item
SaveItemType(ItemType)
Saves the item type
public void SaveItemType(ItemType itemType)
Parameters
itemType
ItemTypeThe 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
masterItem
ItemThe master item
languageItem
ItemThe language item
fieldName
stringThe 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
itemType
stringThe itemtype of the item to update sort index
itemId
stringThe id of the item to update sort index
sortIndex
intThe 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)