Class ItemService
- Namespace
- Dynamicweb.Content
- Assembly
- Dynamicweb.dll
Provides methods for querying and persisting items.
- Inheritance
-
Item
Service
- 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
Parameters
itemType
stringType of the item.
itemId
stringThe item identifier.
sort
intThe sort index of the item.
context
ItemContext The item context.
Returns
- Item
Entry 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
Parameters
page
PageThe page from which to make a copy of it's associated Item
Returns
- Item
Entry 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
Parameters
paragraph
ParagraphThe paragraph from which to make a copy of it's associated Item
Returns
- Item
Entry 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.
Parameters
itemType
ItemType The item type to customize. The item type customization is only available for Websites, Pages, and Paragraphs.
Returns
DeleteItemTypes(IEnumerable<string>, string)
Parameters
itemSystemNames
IEnumerable<string>deleteMode
string
GetItem(string, string)
Gets the item.
Parameters
Returns
- Item
ItemEntry.
GetItem(string, string, bool)
Gets the item.
Parameters
Returns
- Item
ItemEntry.
GetItem(string, string, bool, DateTime)
Gets the item.
Parameters
itemType
stringType of the item.
itemId
stringThe item identifier.
draft
boolLook for draft
previewDate
DateTime Date of preview
Returns
- Item
ItemEntry.
GetItemById<T>(string)
Parameters
itemId
string
Returns
- T
Type Parameters
T
GetItemByPageId(int, bool)
Gets page item by the given page Id.
Parameters
Returns
- Item
Item with the given Id.
GetItemByPageId(int, bool, DateTime)
Gets page item by the given page Id.
Parameters
pageId
intPage Id.
draft
boolIs item in a draft mode
previewDate
DateTime Date to preview the content from
Returns
- Item
Item with the given Id.
GetTitle(Item)
Returns page title.
Parameters
item
ItemThe item.
Returns
- string
Value to use as page title.
IsItemTypeCustomizable(ItemType)
Determines if the item type is customizable.
Parameters
itemType
ItemType The item type.
Returns
RestoreItem(ItemStoreContainer)
Restores the item entry and related objects.
Parameters
store
ItemStore Container The container to store items and related objects
Exceptions
- Invalid
Operation Exception 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.
Parameters
store
ItemStore Container The container to store items and related objects
generateNewId
bool
SaveItem(ItemEntry)
Saves the new item to persistence
Parameters
item
ItemEntry The item to save to persistence
Returns
- Item
Entry The newly save item
SaveItemType(ItemType)
Saves the item type
Parameters
itemType
ItemType The item type to save
SynchronizeListField(Item, Item, string)
Synchronize list field on language item by master
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
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.
Parameters
UpdateItemTitle(string, string, string)
Updates item field used for page title.