Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Actions

Oskar Dillén edited this page May 7, 2014 · 11 revisions

Each type of action is a sub class of the Action class. The subclasses have a property called Data which contains specific information for that type of action.

As an example, if you want print all create card actions for a board you could do it like this:

var board = trello.Boards.WithId("a board id");
foreach (var action in trello.Actions.ForBoard(board).OfType<CreateCardAction>())
{
    Console.WriteLine(action.Date + " " + action.Data.Card.Name);
}

That will fetch all board actions from trello and then filter in memory. For performance reasons you can tell Trello.NET to only ask for specific action types by passing an additional parameter like this:

foreach (var action in trello.Actions.ForBoard(board, 
    new[] { ActionType.CreateCard }).OfType<CreateCardAction>())
{
    Console.WriteLine(action.Date + " - " + action.Data.Card.Name);
}

Since there can be a lot of actions trello uses paging. You can pass a Paging parameter to tell trello the page index and the page size. The following means that each page is 100 actions and you want the first page (0).

foreach (var action in trello.Actions.ForBoard(board, 
    new[] { ActionType.CreateCard }, 
    paging: new Paging(100, 0)).OfType<CreateCardAction>())
{
    Console.WriteLine(action.Date + " - " + action.Data.Card.Name);
}

There is an extension method called AutoPaged() that will help with the paging. Add a using statement...

using TrelloNet.Extensions;

...and use AutoPaged(). Trello.NET will automatically fetch new pages as needed.

foreach (var action in trello.Actions.AutoPaged().ForBoard(board, 
    new[] { ActionType.CreateCard }).OfType<CreateCardAction>())
{
    Console.WriteLine(action.Date + " - " + action.Data.Card.Name);
}

Note: There has been a while since new action types were added to Trello.NET so there might be new ones that are not recognized...

To add a comment to a card:

trello.Cards.AddComment(aCard, "The comment");

Get all comments from a card:

var comments = trello.Actions
    .AutoPaged(Paging.MaxLimit) // This will make sure that you get all comments
    .ForCard(thisCard, new[] { ActionType.CommentCard }) // This will have trello.com return only comments
    .OfType<CommentCardAction>()
    .Select(a => a.Data.Text);

var strMgs = "Activities:<br/>" + string.Join("<br/>", comments);

Get all the lists a card has been moved between:

var card = trello.Cards.WithId("a card id");

var cardMoves = trello.Actions
	.AutoPaged() // Use this extension method and Trello.NET handles paging
	.ForCard(card, new [] { ActionType.UpdateCard }) // Reduces response size
	.OfType<UpdateCardMoveAction>();

foreach (var cardMove in cardMoves)
{
	Console.WriteLine("Card moved from {0} to {1}.",
		cardMove.Data.ListBefore,
		cardMove.Data.ListAfter);
}
Clone this wiki locally