# Work with dynamic items

## Get a dynamic item

You can get a single item using the `GetItem` method of the `IRestClient` interface.

<SfDetails summary="Get an item">

The following code gets a press release item by its ID:

```C#
using Microsoft.AspNetCore.Mvc;
using Progress.Sitefinity.RestSdk.Dto;
using Progress.Sitefinity.RestSdk;

namespace Renderer.Controllers
{
    public class TestController : Controller
    {
        private IRestClient restClient;

        public TestController(IRestClient restClient)
        {
            this.restClient = restClient;
        }

        public async Task<IActionResult> GetItem()
        {
            var item = await restClient.GetItem<SdkItem>(new GetItemArgs()
            {
                Type = RestClientContentTypes.Pressreleases,
                Id = "ITEM_ID",
                // Fields = "FIELDS_TO_GET" // optional
                // Provider = "PROVIDER_OF_THE_ITEM" // optional
                // Culture = "CULTURE_OF_THE_ITEM" // optional
            });

            return this.Json(item);
        }
    }
}
```

> info  **NOTE**: You can optionally get a field of the item or get it from a particular provider or culture.

</SfDetails>

## Get a collection of dynamic items

You can get a collection of items using the `GetItems` method of the `IRestClient` interface.

<SfDetails summary="Get a collection of items">

The following code gets all items of type press release:

```C#
using Microsoft.AspNetCore.Mvc;
using Progress.Sitefinity.RestSdk.Dto;
using Progress.Sitefinity.RestSdk;

namespace Renderer.Controllers
{
    public class TestController : Controller
    {
        private IRestClient restClient;

        public TestController(IRestClient restClient)
        {
            this.restClient = restClient;
        }

        public async Task<IActionResult> GetItems()
        {
            var items = await restClient.GetItems<SdkItem>(new GetAllArgs()
            {
                Type = RestClientContentTypes.Pressreleases,
                // Fields = "FIELDS_TO_GET" // optional
                // Provider = "PROVIDER_OF_THE_ITEMS" // optional
                // Culture = "CULTURE_OF_THE_ITEMS" // optional
                // Skip = 5 // optional
                // Take = 5 // optional
            });

            return this.Json(items);
        }
    }
}
```

> info  **NOTE**: You can optionally get specific fields of the press release items or get them from a particular provider or culture. You can also skip or take specified number of items in the collection.

</SfDetails>

## Get a collection of dynamic items in order

You can get a collection of items using the `GetItems` method of the `IRestClient` interface and then order the collection by the value of a field.

<SfDetails summary="Get an orderer collection of items">

The following code gets all items of type press release and orders it ascending by the title:

```C#
using Microsoft.AspNetCore.Mvc;
using Progress.Sitefinity.RestSdk.Dto;
using Progress.Sitefinity.RestSdk;

namespace Renderer.Controllers
{
    public class TestController : Controller
    {
        private IRestClient restClient;

        public TestController(IRestClient restClient)
        {
            this.restClient = restClient;
        }

        public async Task<IActionResult> GetItems()
        {
            var items = await restClient.GetItems<SdkItem>(new GetAllArgs()
            {
                Type = RestClientContentTypes.Pressreleases,
                OrderBy = new[]
                {
                    new OrderBy()
                    {
                        Name = "Title",
                        Type = OrderType.Ascending,
                    },
                },
            });

            return this.Json(items);
        }
    }
}
```

</SfDetails>

## Get a filtered collection of dynamic items

You can get a collection of items using the `GetItems` method of the `IRestClient` interface and then filter the collection by the value of one or more fields.

<SfDetails summary="Get a filtered collection of items">

The following code gets all items of type press release and filters it based on its title containg two specified values:

```C#
using Microsoft.AspNetCore.Mvc;
using Progress.Sitefinity.RestSdk.Dto;
using Progress.Sitefinity.RestSdk;
using Progress.Sitefinity.RestSdk.Filters;

namespace Renderer.Controllers
{
    public class TestController : Controller
    {
        private IRestClient restClient;

        public TestController(IRestClient restClient)
        {
            this.restClient = restClient;
        }

        public async Task<IActionResult> GetItems()
        {
            var items = await restClient.GetItems<SdkItem>(new GetAllArgs()
            {
                Type = RestClientContentTypes.Pressreleases,
                Filter = new CombinedFilter()
                {
                    Operator = CombinedFilter.LogicalOperators.Or,
                    ChildFilters = new[]
                    {
                        new FilterClause()
                        {
                            FieldName = "Title",
                            Operator = FilterClause.StringOperators.Contains,
                            FieldValue = "SOME_VALUE",
                        },
                        new FilterClause()
                        {
                            FieldName = "Title",
                            Operator = FilterClause.StringOperators.Contains,
                            FieldValue = "ANOTHER_VALUE",
                        },
                    },
                },
            });
            return this.Json(items);
        }
    }
}
```

</SfDetails>

## Get the parent type of a dynamic item

You can get a collection of items using the `GetParent` method of the `IRestClient` interface.

<SfDetails summary="Get the parent type of an item">

The following code gets the parent type of a an item by providing the item's type:

```C#
var parentType = restClient.ServiceMetadata.GetParentType("ITEM_TYPE_FULL_NAME");
```

</SfDetails>

## Create a dynamic item

You create items using the `CreateItem` method of the `IRestClient` interface.

<SfDetails summary="Create a dynamic item and set the value its custom field">

The following code creates a press release item with title Sample title and sets the value of its `MyCustomFieldName` field to `My custom field value`:

```C#
var item = await restClient.CreateItem<SdkItem>(new CreateArgs()
{
    Type = RestClientContentTypes.Pressreleases,
    Data = new 
    { 
        Title = "Sample title",
        MyCustomFieldName = "My custom field value"
    },
}, /* optional providerName parameter */);
```

> info  **NOTE**: You can optionally provide a provider name, which will create the item in a specified provider.

</SfDetails>

## Create dynamic items relations

You create items using the `RelateItem` method of the `IRestClient` interface.

<SfDetails summary="Add a related data item to a dynamic item">

The following code adds specific related data item to a specified field of a dynamic item:

```C#
await restClient.RelateItem<SdkItem>(new GetAllArgs()
{
    Type = RestClientContentTypes.Pressreleases,
    Id = "ITEM_ID",
    RelationName = "RELATED_FIELD_NAME",
    RelatedItemId = "RELATED_ITEM_ID"
});
```

</SfDetails>

## Update an item

You update items using the `UpdateItem` method of the `IRestClient` interface.

<SfDetails summary="Update a dynamic item with custom fields">

The following code updates the title of the press release with the specified ID to `Sample title` and the value of its `MyCustomFieldName` field to `My custom field value`:

```C#
await restClient.UpdateItem(new UpdateArgs()
{
    Type = RestClientContentTypes.Pressreleases,
    Data = new 
    {
        Id = "ID_OF_THE_ITEM",
        // Privider = "PROVIDER_OF_THE_ITEM" //optional
        Title = "Sample title",
        MyCustomFieldName = "My custom field value"
    },
});
```

</SfDetails>

## Delete an item

You delete items using the `DeleteItem` method of the `IRestClient` interface.

<SfDetails summary="Delete a dynamic item">

The following code deletes the press release with the specified ID:

```C#
await restClient.DeleteItem(new DeleteArgs()
{
    Type = RestClientContentTypes.Pressreleases,
    Id = item.Id,
    // Privider = "PROVIDER_OF_THE_ITEM" //optional
});
```

</SfDetails>
