Documentation

Store

Deprecated: Please note that future versions of ThoughtFarmer will not support RazorEngine and Server C#. Please instead use JavaScript and fetch and update data via ajax and the Public REST API.


The custom card Store allows for key value pairs to be associated with custom cards. Please keep in mind that the value for customPortletUniqueId as part of the API model will be different for each instance of a custom card. If you wish to share data across multiple instances then you can hard code your own unique global ID into the code. 

Read Method

Syntax:

public T Read<T>(int customPortletId, string key)

Parameters:

Parameter Type Description
customPortletId int The custom card template id, or any unique int.
key string The key of the stored item

Return value:

Type Description
T A generic type containing the stored item
 

Examples:

@{
    var userCount = this.Store.Read<int>( 20170627, "user-count-key");
}

ReadAll Method

Syntax:

public IEnumerable<T> ReadAll<T>(int customPortletId)

Parameters:

Parameter Type Description
customPortletId int The custom card id or any unique int

Return value:

Type Description
IEnumerable<T> A dynamic object containing the stored item
 

Examples:

@{
    var dataList = this.Store.ReadAll<dynamic>(20170627);
}


Write Method

Syntax:

public void Write(int customPortletId, string key, string value)

Parameters:

Parameter Type Description
customPortletId int The custom card id or any unique int
key string The key of the item to store
value string The value to store

Return value:

void

Examples:

@{
    var customStoreId = 20170627;

var userCount = this.Api.User.GetAll().Where(user =&gt; user.LastName.StartsWith("Smi")).ToList().Count;
this.Store.Write(customStoreId, "user-count-key", userCount);

}