Add existing labels to a new or existing card

545 views Asked by At

I just started using Manatee.Trello but I managed to get most everything I need working including adding new cards and updating existing.

I'm attempting to add a label that already exists on Trello to a card using Manatee.Trello.

CardID = "cardIDHere";
var card = new Card(CardID);
card.Name = strCardTitle;
card.Description = strCardDesc;
var list = new List("listIDHere");
card.List = list;
var member = new Member("MemberIDHere");
var label = new Label(board,"blue",DateTime.Now,"ID-Here","ProdIssues",1);
card.Labels.Add(label);

Can someone show the proper way to create an instance of that Label class for an existing label?

1

There are 1 answers

2
gregsdennis On BEST ANSWER

Label has an internal constructor. The only way to get an instance of a label is through the Board.Labels collection.

I did this because a label only makes sense in the context of a board. Each board defines its labels, and a label without a board is meaningless.

To get your code working, you just need to access the board's label collection and select the one you want to apply to the card.

...
var label = card.Board.Labels.FirstOrDefault(l => l.Color == LabelColor.Blue);
if (label != null)
    card.Labels.Add(label);

Hope that helps!