• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rwjdk / TrelloDotNet / 5992095035

27 Aug 2023 04:43PM UTC coverage: 69.438% (-1.4%) from 70.85%
5992095035

push

github

rwjdk
Version 1.8.0

824 of 1507 branches covered (0.0%)

Branch coverage included in aggregate %.

77 of 77 new or added lines in 9 files covered. (100.0%)

2082 of 2678 relevant lines covered (77.74%)

62.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.8
/TrelloDotNet/TrelloDotNet/TrelloClient.Cards.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text.Json;
5
using System.Threading;
6
using System.Threading.Tasks;
7
using TrelloDotNet.Control;
8
using TrelloDotNet.Model;
9
using TrelloDotNet.Model.Options.GetCardOptions;
10

11
namespace TrelloDotNet
12
{
13
    public partial class TrelloClient
14
    {
15
        /// <summary>
16
        /// Add a Card
17
        /// </summary>
18
        /// <param name="card">The Card to Add</param>
19
        /// <param name="cancellationToken">Cancellation Token</param>
20
        /// <returns>The Added Card</returns>
21
        public async Task<Card> AddCardAsync(Card card, CancellationToken cancellationToken = default)
22
        {
23
            return await _apiRequestController.Post<Card>($"{UrlPaths.Cards}", cancellationToken, _queryParametersBuilder.GetViaQueryParameterAttributes(card));
56✔
24
        }
56✔
25

26
        /// <summary>
27
        /// Archive (Close) a Card
28
        /// </summary>
29
        /// <param name="cardId">The id of card that should be archived</param>
30
        /// <param name="cancellationToken">Cancellation Token</param>
31
        /// <returns>The Archived Card</returns>
32
        public async Task<Card> ArchiveCardAsync(string cardId, CancellationToken cancellationToken = default)
33
        {
34
            return await _apiRequestController.Put<Card>($"{UrlPaths.Cards}/{cardId}", cancellationToken, new QueryParameter("closed", true));
1✔
35
        }
1✔
36

37
        /// <summary>
38
        /// ReOpen (Send back to board) a Card
39
        /// </summary>
40
        /// <param name="cardId">The id of card that should be reopened</param>
41
        /// <param name="cancellationToken">Cancellation Token</param>
42
        /// <returns>The ReOpened Card</returns>
43
        public async Task<Card> ReOpenCardAsync(string cardId, CancellationToken cancellationToken = default)
44
        {
45
            return await _apiRequestController.Put<Card>($"{UrlPaths.Cards}/{cardId}", cancellationToken, new QueryParameter(@"closed", false));
1✔
46
        }
1✔
47

48
        /// <summary>
49
        /// Update a Card
50
        /// </summary>
51
        /// <param name="cardWithChanges">The card with the changes</param>
52
        /// <param name="cancellationToken">Cancellation Token</param>
53
        /// <returns>The Updated Card</returns>
54
        public async Task<Card> UpdateCardAsync(Card cardWithChanges, CancellationToken cancellationToken = default)
55
        {
56
            var parameters = _queryParametersBuilder.GetViaQueryParameterAttributes(cardWithChanges).ToList();
34✔
57
            //Special code for Cover
58
            string payload = string.Empty;
34✔
59
            if (cardWithChanges.Cover == null)
34✔
60
            {
61
                //Remove cover
62
                parameters.Add(new QueryParameter(@"cover", ""));
3✔
63
            }
64
            else
65
            {
66
                cardWithChanges.Cover.PrepareForAddUpdate();
31✔
67
                if (cardWithChanges.Cover.Color != null || cardWithChanges.Cover.BackgroundImageId != null)
31✔
68
                {
69
                    parameters.Remove(parameters.First(x => x.Name == "idAttachmentCover")); //This parameter can't be there while a cover is added
42✔
70
                }
71

72
                payload = $"{{\"cover\":{JsonSerializer.Serialize(cardWithChanges.Cover)}}}";
31✔
73
            }
74

75
            return await _apiRequestController.PutWithJsonPayload<Card>($"{UrlPaths.Cards}/{cardWithChanges.Id}", cancellationToken, payload, parameters.ToArray());
34✔
76
        }
34✔
77

78
        /// <summary>
79
        /// Archive all cards on in a List
80
        /// </summary>
81
        /// <param name="listId">The id of the List that should have its cards archived</param>
82
        /// <param name="cancellationToken">Cancellation Token</param>
83
        public async Task ArchiveAllCardsInListAsync(string listId, CancellationToken cancellationToken = default)
84
        {
85
            await _apiRequestController.Post<List>($"{UrlPaths.Lists}/{listId}/archiveAllCards", cancellationToken);
1✔
86
        }
1✔
87

88
        /// <summary>
89
        /// Move all cards of a list to another list
90
        /// </summary>
91
        /// <param name="currentListId">The id of the List that should have its cards moved</param>
92
        /// <param name="newListId">The id of the new List that should receive the cards</param>
93
        /// <param name="cancellationToken">Cancellation Token</param>
94
        public async Task MoveAllCardsInListAsync(string currentListId, string newListId, CancellationToken cancellationToken = default)
95
        {
96
            var newList = await GetListAsync(newListId, cancellationToken); //Get the new list's BoardId so the user do not need to provide it.
1✔
97
            await _apiRequestController.Post($"{UrlPaths.Lists}/{currentListId}/moveAllCards", cancellationToken,
1✔
98
                0,
1✔
99
                new QueryParameter(@"idBoard", newList.BoardId),
1✔
100
                new QueryParameter(@"idList", newListId)
1✔
101
            );
1✔
102
        }
1✔
103

104
        /// <summary>
105
        /// Delete a Card (WARNING: THERE IS NO WAY GOING BACK!!!). Alternative use ArchiveCardAsync() for non-permanency
106
        /// </summary>
107
        /// <param name="cardId">The id of the Card to Delete</param>
108
        /// <param name="cancellationToken">Cancellation Token</param>
109
        public async Task DeleteCardAsync(string cardId, CancellationToken cancellationToken = default)
110
        {
111
            await _apiRequestController.Delete($"{UrlPaths.Cards}/{cardId}", cancellationToken, 0);
1✔
112
        }
1✔
113

114
        /// <summary>
115
        /// Get a Card by its Id
116
        /// </summary>
117
        /// <param name="cardId">Id of the Card</param>
118
        /// <param name="cancellationToken">Cancellation Token</param>
119
        /// <returns>The Card</returns>
120
        public async Task<Card> GetCardAsync(string cardId, CancellationToken cancellationToken = default)
121
        {
122
            return await _apiRequestController.Get<Card>($"{UrlPaths.Cards}/{cardId}", cancellationToken,
111✔
123
                new QueryParameter(@"customFieldItems", Options.IncludeCustomFieldsInCardGetMethods),
111✔
124
                new QueryParameter(@"attachments", Options.IncludeAttachmentsInCardGetMethods)
111✔
125
            );
111✔
126
        }
111✔
127

128
        /// <summary>
129
        /// Get a Card by its Id
130
        /// </summary>
131
        /// <param name="cardId">Id of the Card</param>
132
        /// <param name="options">Options on how and what should be included on the cards (Example only a few fields to increase performance or more nested data to avoid more API calls)</param>
133
        /// <param name="cancellationToken">Cancellation Token</param>
134
        /// <returns>The Card</returns>
135
        public async Task<Card> GetCardAsync(string cardId, GetCardOptions options, CancellationToken cancellationToken = default)
136
        {
137
            return await _apiRequestController.Get<Card>($"{UrlPaths.Cards}/{cardId}", cancellationToken, options.GetParameters());
×
138
        }
×
139

140
        /// <summary>
141
        /// Get all open cards on un-archived lists on a board
142
        /// </summary>
143
        /// <param name="boardId">Id of the Board (in its long or short version)</param>
144
        /// <param name="cancellationToken">CancellationToken</param>
145
        /// <returns>List of Cards</returns>
146
        public async Task<List<Card>> GetCardsOnBoardAsync(string boardId, CancellationToken cancellationToken = default)
147
        {
148
            return await _apiRequestController.Get<List<Card>>($"{UrlPaths.Boards}/{boardId}/{UrlPaths.Cards}/", cancellationToken,
6✔
149
                new QueryParameter("customFieldItems", Options.IncludeCustomFieldsInCardGetMethods),
6✔
150
                new QueryParameter("attachments", Options.IncludeAttachmentsInCardGetMethods)
6✔
151
                );
6✔
152
        }
6✔
153

154
        /// <summary>
155
        /// Get all open cards on un-archived lists on a board
156
        /// </summary>
157
        /// <param name="boardId">Id of the Board (in its long or short version)</param>
158
        /// <param name="options">Options on how and what should be included on the cards (Example only a few fields to increase performance or more nested data to avoid more API calls)</param>
159
        /// <param name="cancellationToken">CancellationToken</param>
160
        /// <returns>List of Cards</returns>
161
        public async Task<List<Card>> GetCardsOnBoardAsync(string boardId, GetCardOptions options, CancellationToken cancellationToken = default)
162
        {
163
            return await _apiRequestController.Get<List<Card>>($"{UrlPaths.Boards}/{boardId}/{UrlPaths.Cards}/", cancellationToken, options.GetParameters());
×
164
        }
×
165

166
        /// <summary>
167
        /// Get all open cards on a specific list
168
        /// </summary>
169
        /// <param name="listId">Id of the List</param>
170
        /// <param name="cancellationToken">Cancellation Token</param>
171
        /// <returns>List of Cards</returns>
172
        public async Task<List<Card>> GetCardsInListAsync(string listId, CancellationToken cancellationToken = default)
173
        {
174
            return await _apiRequestController.Get<List<Card>>($"{UrlPaths.Lists}/{listId}/{UrlPaths.Cards}/", cancellationToken,
9✔
175
                new QueryParameter(@"customFieldItems", Options.IncludeCustomFieldsInCardGetMethods),
9✔
176
                new QueryParameter(@"attachments", Options.IncludeAttachmentsInCardGetMethods));
9✔
177
        }
9✔
178

179
        /// <summary>
180
        /// Get all open cards on a specific list
181
        /// </summary>
182
        /// <param name="listId">Id of the List</param>
183
        /// <param name="options">Options on how and what should be included on the cards (Example only a few fields to increase performance or more nested data to avoid more API calls)</param>
184
        /// <param name="cancellationToken">Cancellation Token</param>
185
        /// <returns>List of Cards</returns>
186
        public async Task<List<Card>> GetCardsInListAsync(string listId, GetCardOptions options, CancellationToken cancellationToken = default)
187
        {
188
            return await _apiRequestController.Get<List<Card>>($"{UrlPaths.Lists}/{listId}/{UrlPaths.Cards}/", cancellationToken, options.GetParameters());
×
189
        }
×
190

191
        /// <summary>
192
        /// Get the cards on board based on their status regardless if they are on archived lists
193
        /// </summary>
194
        /// <param name="boardId">Id of the Board (in its long or short version)</param>
195
        /// <param name="filter">The Selected Filter</param>
196
        /// <param name="cancellationToken">Cancellation Token</param>
197
        /// <returns>List of Cards</returns>
198
        public async Task<List<Card>> GetCardsOnBoardFilteredAsync(string boardId, CardsFilter filter, CancellationToken cancellationToken = default)
199
        {
200
            return await _apiRequestController.Get<List<Card>>($"{UrlPaths.Boards}/{boardId}/{UrlPaths.Cards}/{filter.GetJsonPropertyName()}", cancellationToken,
1✔
201
                new QueryParameter(@"customFieldItems", Options.IncludeCustomFieldsInCardGetMethods),
1✔
202
                new QueryParameter(@"attachments", Options.IncludeAttachmentsInCardGetMethods));
1✔
203
        }
1✔
204

205
        /// <summary>
206
        /// Get the cards on board based on their status regardless if they are on archived lists
207
        /// </summary>
208
        /// <param name="boardId">Id of the Board (in its long or short version)</param>
209
        /// <param name="filter">The Selected Filter</param>
210
        /// <param name="options">Options on how and what should be included on the cards (Example only a few fields to increase performance or more nested data to avoid more API calls)</param> 
211
        /// <param name="cancellationToken">Cancellation Token</param>
212
        /// <returns>List of Cards</returns>
213
        public async Task<List<Card>> GetCardsOnBoardFilteredAsync(string boardId, CardsFilter filter, GetCardOptions options, CancellationToken cancellationToken = default)
214
        {
215
            return await _apiRequestController.Get<List<Card>>($"{UrlPaths.Boards}/{boardId}/{UrlPaths.Cards}/{filter.GetJsonPropertyName()}", cancellationToken, options.GetParameters());
×
216
        }
×
217

218
        /// <summary>
219
        /// Get all Cards a Member is on (across multiple boards)
220
        /// </summary>
221
        /// <param name="memberId">Id of Member</param>
222
        /// <param name="cancellationToken">Cancellation Token</param>
223
        /// <returns></returns>
224
        public async Task<List<Card>> GetCardsForMemberAsync(string memberId, CancellationToken cancellationToken = default)
225
        {
226
            return await _apiRequestController.Get<List<Card>>($"{UrlPaths.Members}/{memberId}/{UrlPaths.Cards}", cancellationToken);
1✔
227
        }
1✔
228

229
        /// <summary>
230
        /// Get all Cards a Member is on (across multiple boards)
231
        /// </summary>
232
        /// <param name="memberId">Id of Member</param>
233
        /// <param name="options">Options on how and what should be included on the cards (Example only a few fields to increase performance or more nested data to avoid more API calls)</param>
234
        /// <param name="cancellationToken">Cancellation Token</param>
235
        /// <returns></returns>
236
        public async Task<List<Card>> GetCardsForMemberAsync(string memberId, GetCardOptions options, CancellationToken cancellationToken = default)
237
        {
238
            return await _apiRequestController.Get<List<Card>>($"{UrlPaths.Members}/{memberId}/{UrlPaths.Cards}", cancellationToken, options.GetParameters());
×
239
        }
×
240

241
        /// <summary>
242
        /// Set Due Date on a card
243
        /// </summary>
244
        /// <param name="cardId">Id of the Card</param>
245
        /// <param name="dueDate">The Due Date (In UTC Time)</param>
246
        /// <param name="dueComplete">If Due is complete</param>
247
        /// <param name="cancellationToken">Cancellation Token</param>
248
        public async Task<Card> SetDueDateOnCardAsync(string cardId, DateTimeOffset dueDate, bool dueComplete = false, CancellationToken cancellationToken = default)
249
        {
250
            var card = await GetCardAsync(cardId, cancellationToken);
1✔
251
            card.Due = dueDate;
1✔
252
            card.DueComplete = dueComplete;
1✔
253
            return await UpdateCardAsync(card, cancellationToken);
1✔
254
        }
1✔
255

256
        /// <summary>
257
        /// Set Due Date on a card
258
        /// </summary>
259
        /// <param name="cardId">Id of the Card</param>
260
        /// <param name="startDate">The Start Date (In UTC Time)</param>
261
        /// <param name="cancellationToken">Cancellation Token</param>
262
        public async Task<Card> SetStartDateOnCardAsync(string cardId, DateTimeOffset startDate, CancellationToken cancellationToken = default)
263
        {
264
            var card = await GetCardAsync(cardId, cancellationToken);
1✔
265
            card.Start = startDate;
1✔
266
            return await UpdateCardAsync(card, cancellationToken);
1✔
267
        }
1✔
268

269
        /// <summary>
270
        /// Set Start and Due Date on a card
271
        /// </summary>
272
        /// <param name="cardId">Id of the Card</param>
273
        /// <param name="startDate">The Start Date (In UTC Time)</param>
274
        /// <param name="dueDate">The Due Date (In UTC Time)</param>
275
        /// <param name="dueComplete">If Due is complete</param>
276
        /// <param name="cancellationToken">Cancellation Token</param> 
277
        public async Task<Card> SetStartDateAndDueDateOnCardAsync(string cardId, DateTimeOffset startDate, DateTimeOffset dueDate, bool dueComplete = false, CancellationToken cancellationToken = default)
278
        {
279
            var card = await GetCardAsync(cardId, cancellationToken);
1✔
280
            card.Start = startDate;
1✔
281
            card.Due = dueDate;
1✔
282
            card.DueComplete = dueComplete;
1✔
283
            return await UpdateCardAsync(card, cancellationToken);
1✔
284
        }
1✔
285

286
        /// <summary>
287
        /// Move a Card to a new list on the same board
288
        /// </summary>
289
        /// <param name="cardId">Id of the Card</param>
290
        /// <param name="newListId">Id of the List you wish to move it to</param>
291
        /// <param name="cancellationToken">Cancellation Token</param>
292
        /// <returns></returns>
293
        public async Task<Card> MoveCardToListAsync(string cardId, string newListId, CancellationToken cancellationToken = default)
294
        {
295
            Card card = await GetCardAsync(cardId, cancellationToken);
1✔
296
            card.ListId = newListId;
1✔
297
            return await UpdateCardAsync(card, cancellationToken);
1✔
298
        }
1✔
299
    }
300
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc