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 sealed class ItemServiceSample
{
public static IList<ItemEntry> CreateItems()
{
var service = 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
[
news,
newsCopy,
genericCopy
];
}
public static ItemEntry? CopyItem(string itemType, string itemId)
{
Item? item = Services.Items.GetItem(itemType, itemId);
if (item is null)
return null;
return Services.Items.SaveItem(item.Copy());
}
public static ItemEntry? CopyPageItem(Page page)
{
ItemEntry? item = Services.Items.CopyPageItem(page);
if (item is not null)
item = Services.Items.SaveItem(item);
return item;
}
public static ItemEntry? CopyParagraphItem(Paragraph paragraph)
{
ItemEntry? item = Services.Items.CopyParagraphItem(paragraph);
if (item is not null)
item = Services.Items.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
itemTypestringType of the item.
itemIdstringThe item identifier.
sortintThe sort index of the item.
contextItemContextThe 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
pagePageThe 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
paragraphParagraphThe 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
itemTypeItemTypeThe 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
itemTypestringType of the item.
itemIdstringThe item identifier.
draftboolLook for draft
previewDateDateTimeDate of preview
Returns
- Item
ItemEntry.
GetItemById<T>(string)
public T? GetItemById<T>(string itemId) where T : ItemEntry, new()
Parameters
itemIdstring
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
pageIdintPage Id.
draftboolIs item in a draft mode
previewDateDateTimeDate to preview the content from
Returns
- Item
Item with the given Id.
GetTitle(Item)
Returns page title.
public string GetTitle(Item item)
Parameters
itemItemThe item.
Returns
- string
Value to use as page title.
IsItemCreationAllowed<T>(string)
Checks if the item restriction rule is allowed
public bool IsItemCreationAllowed<T>(string itemTypeSystemName) where T : CreationRule
Parameters
itemTypeSystemNamestringThe item type system name
Returns
- bool
True if the restriction rule is allowed, otherwise false
Type Parameters
TType of restriction rule
IsItemCreationAllowed<T, TEnum>(string, TEnum)
Checks if the item restriction rule contains specified value
public bool IsItemCreationAllowed<T, TEnum>(string itemTypeSystemName, TEnum ruleValue) where T : CreationRule where TEnum : struct, Enum
Parameters
itemTypeSystemNamestringThe item type system name
ruleValueTEnumThe value of a restriction rule
Returns
- bool
True if the specified value is allowed by rule, otherwise false
Type Parameters
TType of restriction rule
TEnumType of the enum which represent the rule values
IsItemTypeCustomizable(ItemType)
Determines if the item type is customizable.
public bool IsItemTypeCustomizable(ItemType itemType)
Parameters
itemTypeItemTypeThe item type.
Returns
RestoreItem(ItemStoreContainer)
Restores the item entry and related objects.
public void RestoreItem(ItemStoreContainer store)
Parameters
storeItemStoreContainerThe 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
storeItemStoreContainerThe container to store items and related objects
generateNewIdbool
SaveItem(ItemEntry)
Saves the new item to persistence
public ItemEntry SaveItem(ItemEntry item)
Parameters
itemItemEntryThe item to save to persistence
Returns
- ItemEntry
The newly save item
SaveItemType(ItemType)
Saves the item type
public void SaveItemType(ItemType itemType)
Parameters
itemTypeItemTypeThe 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
masterItemItemThe master item
languageItemItemThe language item
fieldNamestringThe 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
itemTypestringThe itemtype of the item to update sort index
itemIdstringThe id of the item to update sort index
sortIndexintThe 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)