/// <summary> /// Adds a member to a board with specified privileges. /// </summary> /// <param name="member">The member to add.</param> /// <param name="membership">The membership type.</param> /// <param name="ct">(Optional) A cancellation token for async processing.</param> /// <returns>The <see cref="IBoardMembership"/> generated by Trello.</returns> public async Task <IBoardMembership> Add(IMember member, BoardMembershipType membership, CancellationToken ct = default) { var error = NotNullRule <IMember> .Instance.Validate(null, member); if (error != null) { throw new ValidationException <IMember>(member, new[] { error }); } var json = TrelloConfiguration.JsonFactory.Create <IJsonBoardMembership>(); json.Member = ((Member)member).Json; json.MemberType = membership; var endpoint = EndpointFactory.Build(EntityRequestType.Board_Write_AddOrUpdateMember, new Dictionary <string, object> { { "_id", OwnerId }, { "_memberId", member.Id } }); var newData = await JsonRepository.Execute(Auth, endpoint, json, ct); if (TrelloConfiguration.EnableConsistencyProcessing && member.Boards is ReadOnlyCollection <IBoard> boardCollection) { var board = TrelloConfiguration.Cache.OfType <IBoard>().FirstOrDefault(b => b.Id == OwnerId); if (board != null) { boardCollection.Items.Add(board); } } return(new BoardMembership(newData, OwnerId, Auth)); }
/// <summary> /// Adds a member to a board with specified privileges. /// </summary> /// <param name="member">The member to add.</param> /// <param name="membership">The membership type.</param> public BoardMembership Add(Member member, BoardMembershipType membership) { var error = NotNullRule <Member> .Instance.Validate(null, member); if (error != null) { throw new ValidationException <Member>(member, new[] { error }); } var json = TrelloConfiguration.JsonFactory.Create <IJsonBoardMembership>(); json.Member = member.Json; json.MemberType = membership; var endpoint = EndpointFactory.Build(EntityRequestType.Board_Write_AddOrUpdateMember, new Dictionary <string, object> { { "_id", OwnerId }, { "_memberId", member.Id } }); var newData = JsonRepository.Execute(Auth, endpoint, json); return(new BoardMembership(newData, OwnerId, Auth)); }