Progress will discontinue Telerik Platform on May 10th, 2018. Learn more

Creating Data Items

Creating Data Items

The Backend Services .NET SDK allows you to create data items programmatically. The content type in which you are creating the items must exist.

To create items in a Telerik Platform content type, first create an instance of the class that you have defined for the content type as discussed in Working with Telerik Platform Data. Then pass the instantiated object to the Create() method.

On success, the server returns the ID of the created item alongside its creation date. The values will be automatically set to the objects that you passed.

Creating a Single Item

Use the Create() method to create a new content type item.

public async Task CreateSingleItem(EverliveApp app)
{
    var activity = new Activity();
    activity.Text = "Activity Text";
    await app.WorkWith().Data<Activity>().Create(activity).ExecuteAsync();
    Debug.WriteLine("Item ID: " + activity.Id);
}

Normally, you don't need to specify the item ID—a GUID will be generated for you. However, if you need to set a specific ID, such as when importing existing data from an external database, you can do that by simply passing it with the request. Your custom ID must meet the following conditions:

  • Must be unique inside the application
  • Must be a string
activity.Id = "008541a0-b38a-11e5-84b2-b9c8b2734ef4";
activity.Text = "Activity Text";

You can update system fields such as CreatedAt and CreatedBy. However, you can set them only after doing the following:

EverliveAppSettings appSettings = new EverliveAppSettings() { AppId = "your-app-id", SendSystemPropertiesToServer = true };
var app = new EverliveApp(appSettings);
var masterKey = "your-master-key";
app.AccessToken = new AccessToken(masterKey, "MasterKey");
public async Task CreateSingleItem(app)
{
    var activity = new Activity();
    activity.Id = "008541a0-b38a-11e5-84b2-b9c8b2734ef4";
    activity.Text = "Activity Text";
    activity.CreatedBy = "19baf610-b38a-11e5-a09d-2f9e6ef2405f";
    await app.WorkWith().Data<Activity>().Create(activity).ExecuteAsync();
}

Creating Multiple Items

If you want to create more that one item in a single call, include them in a collection or an array before passing it to the Create() method.

public async Task CreateMultipleItems(EverliveApp app)
{
    var activity = new Activity();
    activity.Text = "Activity Text";
    var activity2 = new Activity();
    activity2.Text = "Activity Text 2";

    var activities = new List<Activity>();
    activities.Add(activity);
    activities.Add(activity2);

    var multipleResult = await app.WorkWith().Data<Activity>().Create(activities).ExecuteAsync();

    foreach(var createdActivity in multipleResult)
    {
        Debug.WriteLine("Item ID: " + createdActivity.Id);
    }
}

Telerik Platform verifies fields marked as unique (IsUnique) just before creating each item. It keeps creating items until it reaches a duplicate value, after which it stops executing the request and returns an error. The rest of the items are not processed.

See Also

Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.