Table of Contents

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

itemType string
Type of the item.
itemId string
The item identifier.
sort int
The sort index of the item.
context ItemContext
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

page Page
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

paragraph Paragraph
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

itemType ItemType
The item type to customize. The item type customization is only available for Websites, Pages, and Paragraphs.

Returns

ItemType

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

itemType string
Type of the item.
itemId string
The item identifier.

Returns

Item
ItemEntry.

GetItem(string, string, bool)

Gets the item.
public Item GetItem(string itemType, string itemId, bool draft)

Parameters

itemType string
Type of the item.
itemId string
The item identifier.
draft bool
Look for draft

Returns

Item
ItemEntry.

GetItem(string, string, bool, DateTime)

Gets the item.
public Item GetItem(string itemType, string itemId, bool draft, DateTime previewDate)

Parameters

itemType string
Type of the item.
itemId string
The item identifier.
draft bool
Look for draft
previewDate DateTime
Date of preview

Returns

Item
ItemEntry.

GetItemById<T>(string)

Gets the item.
public T GetItemById<T>(string itemId) where T : ItemEntry, new()

Parameters

itemId string
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

pageId int
Page Id.
draft bool
Is item in a draft mode

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 int
Page Id.
draft bool
Is 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.
public string GetTitle(Item item)

Parameters

item Item
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

itemType ItemType
The item type.

Returns

bool

MoveToBin(ItemEntry)

Moves the specified item, linked items and items from related list to the bin
public Guid MoveToBin(ItemEntry obj)

Parameters

obj ItemEntry
The item entry to move to the bin

Returns

Guid

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

obj ItemEntry
The item entry to move to a bin
unitId Guid

Restore(object)

Restores the item entry and related objects.
public void Restore(object id)

Parameters

id object
The id of the item entry to restore

RestoreItem(ItemStoreContainer)

Restores the item entry and related objects.
public void RestoreItem(ItemStoreContainer store)

Parameters

store ItemStoreContainer
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

store ItemStoreContainer
The container to store items and related objects
generateNewId bool

SaveItem(ItemEntry)

Saves the new item to persistence
public ItemEntry SaveItem(ItemEntry item)

Parameters

item ItemEntry
The item to save to persistence

Returns

ItemEntry
The newly save item

SaveItemType(ItemType)

Saves the item type
public void SaveItemType(ItemType itemType)

Parameters

itemType ItemType
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

masterItem Item
The master item
languageItem Item
The language item
fieldName string
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

itemType string
The itemtype of the item to update sort index
itemId string
The id of the item to update sort index
sortIndex int
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

itemMetaType ItemType
The itemtype of the item
item Item
The item.
title string
The page title

UpdateItemTitle(string, string, string)

Updates item field used for page title.
public void UpdateItemTitle(string itemType, string itemId, string title)

Parameters

itemType string
The itemtype of the item
itemId string
The id of the item
title string
The page title
To top