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

rwjdk / TrelloDotNet / 13662485221

04 Mar 2025 08:37PM UTC coverage: 67.357% (-4.7%) from 72.018%
13662485221

push

github

rwjdk
Removed [ExcludeFromCodeCoverage] (Not the right way to approch this)

2001 of 3425 branches covered (58.42%)

Branch coverage included in aggregate %.

3820 of 5217 relevant lines covered (73.22%)

91.52 hits per line

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

94.2
/src/TrelloDotNet/TrelloClient.Members.cs
1
using System.Collections.Generic;
2
using System.Diagnostics.CodeAnalysis;
3
using System.Linq;
4
using System.Threading;
5
using System.Threading.Tasks;
6
using TrelloDotNet.Control;
7
using TrelloDotNet.Model;
8
using TrelloDotNet.Model.Options.GetMemberOptions;
9

10
// ReSharper disable UnusedMember.Global
11

12
namespace TrelloDotNet
13
{
14
    public partial class TrelloClient
15
    {
16
        /// <summary>
17
        /// Get the Members (users) of a board
18
        /// </summary>
19
        /// <param name="boardId">Id of the Board (in its long or short version)</param>
20
        /// <param name="cancellationToken">Cancellation Token</param>
21
        /// <returns>List of Members</returns>
22
        public async Task<List<Member>> GetMembersOfBoardAsync(string boardId, CancellationToken cancellationToken = default)
23
        {
24
            return await _apiRequestController.Get<List<Member>>(GetUrlBuilder.GetMembersOfBoard(boardId), cancellationToken);
26✔
25
        }
26✔
26

27
        /// <summary>
28
        /// Get the Members (users) of a board
29
        /// </summary>
30
        /// <param name="boardId">Id of the Board (in its long or short version)</param>
31
        /// <param name="options">Option for what data to include on the Member</param>
32
        /// <param name="cancellationToken">Cancellation Token</param>
33
        /// <returns>List of Members</returns>
34
        public async Task<List<Member>> GetMembersOfBoardAsync(string boardId, GetMemberOptions options, CancellationToken cancellationToken = default)
35
        {
36
            return await _apiRequestController.Get<List<Member>>(GetUrlBuilder.GetMembersOfBoard(boardId), cancellationToken, options.GetParameters());
1✔
37
        }
1✔
38

39
        /// <summary>
40
        /// Get the Members (users) who voted on a Card
41
        /// </summary>
42
        /// <param name="cardId">Id of the Card</param>
43
        /// <param name="cancellationToken">Cancellation Token</param>
44
        /// <returns>List of Members who voted</returns>
45
        public async Task<List<Member>> GetMembersWhoVotedOnCardAsync(string cardId, CancellationToken cancellationToken = default)
46
        {
47
            return await _apiRequestController.Get<List<Member>>(GetUrlBuilder.GetMembersWhoVotedOnOfCard(cardId), cancellationToken);
1✔
48
        }
1✔
49

50
        /// <summary>
51
        /// Get the Members (users) who voted on a Card
52
        /// </summary>
53
        /// <param name="cardId">Id of the Card</param>
54
        /// <param name="options">Option for what data to include on the Member</param>
55
        /// <param name="cancellationToken">Cancellation Token</param>
56
        /// <returns>List of Members who voted</returns>
57
        public async Task<List<Member>> GetMembersWhoVotedOnCardAsync(string cardId, GetMemberOptions options, CancellationToken cancellationToken = default)
58
        {
59
            return await _apiRequestController.Get<List<Member>>(GetUrlBuilder.GetMembersWhoVotedOnOfCard(cardId), cancellationToken, options.GetParameters());
1✔
60
        }
1✔
61

62
        /// <summary>
63
        /// Get the Members (users) of a Card
64
        /// </summary>
65
        /// <param name="cardId">Id of the Card</param>
66
        /// <param name="cancellationToken">Cancellation Token</param>
67
        /// <returns>List of Members</returns>
68
        public async Task<List<Member>> GetMembersOfCardAsync(string cardId, CancellationToken cancellationToken = default)
69
        {
70
            return await _apiRequestController.Get<List<Member>>(GetUrlBuilder.GetMembersOfCard(cardId), cancellationToken);
2✔
71
        }
2✔
72

73
        /// <summary>
74
        /// Get the Members (users) of a Card
75
        /// </summary>
76
        /// <param name="cardId">Id of the Card</param>
77
        /// <param name="options">Option for what data to include on the Member</param>
78
        /// <param name="cancellationToken">Cancellation Token</param>
79
        /// <returns>List of Members</returns>
80
        public async Task<List<Member>> GetMembersOfCardAsync(string cardId, GetMemberOptions options, CancellationToken cancellationToken = default)
81
        {
82
            return await _apiRequestController.Get<List<Member>>(GetUrlBuilder.GetMembersOfCard(cardId), cancellationToken, options.GetParameters());
1✔
83
        }
1✔
84

85
        /// <summary>
86
        /// Get a Member with a specific Id
87
        /// </summary>
88
        /// <param name="memberId">Id of the Member</param>
89
        /// <param name="cancellationToken">Cancellation Token</param>
90
        /// <returns>The Member</returns>
91
        public async Task<Member> GetMemberAsync(string memberId, CancellationToken cancellationToken = default)
92
        {
93
            return await _apiRequestController.Get<Member>(GetUrlBuilder.GetMember(memberId), cancellationToken);
1✔
94
        }
1✔
95

96
        /// <summary>
97
        /// Add one or more Members to a Card
98
        /// </summary>
99
        /// <param name="cardId">Id of the Card</param>
100
        /// <param name="memberIdsToAdd">One or more Ids of Members to add</param>
101
        public async Task<Card> AddMembersToCardAsync(string cardId, params string[] memberIdsToAdd)
102
        {
103
            return await AddMembersToCardAsync(cardId, CancellationToken.None, memberIdsToAdd);
15✔
104
        }
15✔
105

106
        /// <summary>
107
        /// Add one or more Members to a Card
108
        /// </summary>
109
        /// <param name="cardId">Id of the Card</param>
110
        /// <param name="cancellationToken">Cancellation Token</param>
111
        /// <param name="memberIdsToAdd">One or more Ids of Members to add</param>
112
        public async Task<Card> AddMembersToCardAsync(string cardId, CancellationToken cancellationToken = default, params string[] memberIdsToAdd)
113
        {
114
            var card = await GetCardAsync(cardId, cancellationToken);
15✔
115
            var missing = memberIdsToAdd.Where(x => !card.MemberIds.Contains(x)).ToList();
30✔
116

117
            if (missing.Count == 0)
15✔
118
            {
119
                return card; //Everyone already There
1✔
120
            }
121

122
            //Need update
123
            card.MemberIds.AddRange(missing);
14✔
124
            return await UpdateCardAsync(cardId, new List<CardUpdate>
14✔
125
            {
14✔
126
                CardUpdate.Members(card.MemberIds)
14✔
127
            }, cancellationToken);
14✔
128
        }
15✔
129

130
        /// <summary>
131
        /// Remove a Member of a Card
132
        /// </summary>
133
        /// <param name="cardId">Id of the Card</param>
134
        /// <param name="memberIdsToRemove">One or more Ids of Members to remove</param>
135
        public async Task<Card> RemoveMembersFromCardAsync(string cardId, params string[] memberIdsToRemove)
136
        {
137
            return await RemoveMembersFromCardAsync(cardId, CancellationToken.None, memberIdsToRemove);
3✔
138
        }
3✔
139

140
        /// <summary>
141
        /// Remove one or more Members from a Card
142
        /// </summary>
143
        /// <param name="cardId">Id of the Card</param>
144
        /// <param name="cancellationToken">Cancellation Token</param>
145
        /// <param name="memberIdsToRemove">One or more Ids of Members to remove</param>
146
        public async Task<Card> RemoveMembersFromCardAsync(string cardId, CancellationToken cancellationToken = default, params string[] memberIdsToRemove)
147
        {
148
            var card = await GetCardAsync(cardId, cancellationToken);
3✔
149
            var toRemove = memberIdsToRemove.Where(x => card.MemberIds.Contains(x)).ToList();
6✔
150
            if (toRemove.Count == 0)
3✔
151
            {
152
                return card; //Everyone not there
1✔
153
            }
154

155
            //Need update
156
            card.MemberIds = card.MemberIds.Except(toRemove).ToList();
2✔
157
            return await UpdateCardAsync(cardId, new List<CardUpdate>
2✔
158
            {
2✔
159
                CardUpdate.Members(card.MemberIds)
2✔
160
            }, cancellationToken);
2✔
161
        }
3✔
162

163
        /// <summary>
164
        /// Remove all Members from a Card
165
        /// </summary>
166
        /// <param name="cardId">Id of the Card</param>
167
        /// <param name="cancellationToken">Cancellation Token</param>
168
        public async Task<Card> RemoveAllMembersFromCardAsync(string cardId, CancellationToken cancellationToken = default)
169
        {
170
            return await UpdateCardAsync(cardId, new List<CardUpdate>
2✔
171
            {
2✔
172
                CardUpdate.Members(new List<string>())
2✔
173
            }, cancellationToken);
2✔
174
        }
2✔
175

176
        /// <summary>
177
        /// Add a Member to a board (aka give them access)
178
        /// </summary>
179
        /// <param name="boardId">Id of the Board to give access to</param>
180
        /// <param name="memberId">Id of the Member that need access</param>
181
        /// <param name="membershipType">What type of access the member should be given</param>
182
        /// <param name="allowBillableGuest">Optional param that allows organization admins to add multi-board guests onto a board.</param>
183
        /// <param name="cancellationToken">Cancellation Token</param>
184
        public async Task AddMemberToBoardAsync(string boardId, string memberId, MembershipType membershipType, bool allowBillableGuest = false, CancellationToken cancellationToken = default)
185
        {
186
            await _apiRequestController.Put($"{UrlPaths.Boards}/{boardId}/{UrlPaths.Members}/{memberId}", cancellationToken, 0,
1✔
187
                new QueryParameter("type", membershipType.GetJsonPropertyName()),
1✔
188
                new QueryParameter("allowBillableGuest", allowBillableGuest));
1✔
189
        }
1✔
190

191
        /// <summary>
192
        /// Invite a Member to a board via email (aka give them access)
193
        /// </summary>
194
        /// <param name="boardId">Id of the Board to give access to</param>
195
        /// <param name="email">Email to invite</param>
196
        /// <param name="membershipType">What type of access the member should be given</param>
197
        /// <param name="cancellationToken">Cancellation Token</param>
198
        public async Task InviteMemberToBoardViaEmailAsync(string boardId, string email, MembershipType membershipType, CancellationToken cancellationToken = default)
199
        {
200
            await _apiRequestController.Put($"{UrlPaths.Boards}/{boardId}/{UrlPaths.Members}", cancellationToken, 0,
1✔
201
                new QueryParameter("type", membershipType.GetJsonPropertyName()),
1✔
202
                new QueryParameter("email", email));
1✔
203
        }
1✔
204

205
        /// <summary>
206
        /// Remove a Member from a board (aka revoke access)
207
        /// </summary>
208
        /// <param name="boardId">Id of the Board the member should be removed from</param>
209
        /// <param name="memberId">Id of the Member that should be removed</param>
210
        /// <param name="cancellationToken">Cancellation Token</param>
211
        public async Task RemoveMemberFromBoardAsync(string boardId, string memberId, CancellationToken cancellationToken = default)
212
        {
213
            await _apiRequestController.Delete($"{UrlPaths.Boards}/{boardId}/{UrlPaths.Members}/{memberId}", cancellationToken, 0);
1✔
214
        }
1✔
215

216
        /// <summary>
217
        /// Get information about the Member that owns the token used by this TrelloClient
218
        /// </summary>
219
        /// <returns>The Member</returns>
220
        public async Task<Member> GetTokenMemberAsync(CancellationToken cancellationToken = default)
221
        {
222
            return await _apiRequestController.Get<Member>(GetUrlBuilder.GetTokenMember(_apiRequestController.Token), cancellationToken);
19✔
223
        }
19✔
224

225
        /// <summary>
226
        /// Get information about the Member that owns the token used by this TrelloClient
227
        /// <param name="options">Option for what data to include on the Member</param>
228
        /// <param name="cancellationToken">Cancellation Token</param>
229
        /// </summary>
230
        /// <returns>The Member</returns>
231
        public async Task<Member> GetTokenMemberAsync(GetMemberOptions options, CancellationToken cancellationToken = default)
232
        {
233
            return await _apiRequestController.Get<Member>(GetUrlBuilder.GetTokenMember(_apiRequestController.Token), cancellationToken, options.GetParameters());
1✔
234
        }
1✔
235

236
        /// <summary>
237
        /// Get the Members (users) of an Organization (aka Workspace)
238
        /// </summary>
239
        /// <param name="organizationId">Id of the Organization</param>
240
        /// <param name="cancellationToken">Cancellation Token</param>
241
        /// <returns>List of Members</returns>
242
        public async Task<List<Member>> GetMembersOfOrganizationAsync(string organizationId, CancellationToken cancellationToken = default)
243
        {
244
            return await _apiRequestController.Get<List<Member>>(GetUrlBuilder.GetMembersOfOrganization(organizationId), cancellationToken);
1✔
245
        }
1✔
246

247
        /// <summary>
248
        /// Get the Members (users) of an Organization (aka Workspace)
249
        /// </summary>
250
        /// <param name="organizationId">Id of the Organization</param>
251
        /// <param name="options">Option for what data to include on the Member</param>
252
        /// <param name="cancellationToken">Cancellation Token</param>
253
        /// <returns>List of Members</returns>
254
        public async Task<List<Member>> GetMembersOfOrganizationAsync(string organizationId, GetMemberOptions options, CancellationToken cancellationToken = default)
255
        {
256
            return await _apiRequestController.Get<List<Member>>(GetUrlBuilder.GetMembersOfOrganization(organizationId), cancellationToken, options.GetParameters());
1✔
257
        }
1✔
258

259
        /// <summary>
260
        /// Add a member vote to a card
261
        /// </summary>
262
        /// <param name="cardId">The cardId to add the vote to</param>
263
        /// <param name="memberId">The id of the member that cast the vote</param>
264
        /// <param name="cancellationToken">Cancellation Token</param>
265
        public async Task AddVoteToCardAsync(string cardId, string memberId, CancellationToken cancellationToken = default)
266
        {
267
            await _apiRequestController.Post($"{UrlPaths.Cards}/{cardId}/membersVoted", cancellationToken, 0, new QueryParameter("value", memberId));
×
268
        }
×
269

270
        /// <summary>
271
        /// Remove a member vote from a card
272
        /// </summary>
273
        /// <param name="cardId">The cardId to add the vote to</param>
274
        /// <param name="memberId">The id of the member that cast the vote</param>
275
        /// <param name="cancellationToken">Cancellation Token</param>
276
        public async Task RemoveVoteFromCardAsync(string cardId, string memberId, CancellationToken cancellationToken = default)
277
        {
278
            await _apiRequestController.Delete($"{UrlPaths.Cards}/{cardId}/membersVoted/{memberId}", cancellationToken, 0);
×
279
        }
×
280
    }
281
}
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

© 2026 Coveralls, Inc