多次添加同一成员才能与添加卡片trello聚在一起,但不起作用
问题
例如,当我输入相同的用户名时
{ "adwin", "adwin", "robert", "dave"}
如果第一个adwin完成循环添加成员就可以了,那么第二个adwin时间可以添加。
代码退出循环并停止工作。
和
当我输入用户名不在面板中或用户名是假的时。
{ "hghg$*#hgh", "us7s5209hf9", "8shjd76dhj3" }
添加卡完成并添加成员时,它停止工作并退出程序。
完成另一个用户名的添加并非正常工作。
计划
我认为在将成员添加到卡中之前先将其添加到板中是可行的,但以后将不再起作用。
#r"Manatee.Trello.dll"
#r"Manatee.Json.dll"
using System.Net;
using System.ComponentModel;
using System.Drawing;
using System.Windows;
using Manatee.Trello;
using Manatee.Json;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
string Appkey = "df45ee60b0ff10c19377354490f7054b";
string Token = "6af303020a7a4d24d9cf5a1dd8adf2e5ff95c46888b0371c0b2dba45b2a32d7d";
string BoardID = "5b40363293193091c1ba5013";
string ListID = "5b40363293193091c1ba5015";
string name ="CardAddMember";
string description ="desccccc";
string duedate ="2019-08-04";
string iscomplete =true;
string[] user = {"userinboard","notusername","userinboard"};
try
{
DateTime duedatetime = DateTime.Parse(duedate);//time
bool torf = Boolean.Parse(iscomplete);//finish work check
TrelloAuthorization.Default.AppKey = Appkey;
TrelloAuthorization.Default.UserToken = Token;
ITrelloFactory factory = new TrelloFactory();
var List = factory.List(ListID);
var Board = factory.Board(BoardID);
//var MemberType = factory.Board();
char[] commaSeparator = new char[] { ',' };
string[] authors = username.Split(commaSeparator, StringSplitOptions.None);
var card = await List.Cards.Add(name, description, null, duedatetime, torf, null, null);//add card to trello
foreach (string author in authors){
var Member = factory.Member(author);
await Board.Memberships.Add(Member); // Add member in a board but cant add <<<<<<<<<????????
await card.Members.Add(Member); //add member in card
}
var response = new HttpResponseMessage(HttpStatusCode.OK);
return response;
}
catch //find some err [example not find user]
{
return new HttpResponseMessage(HttpStatusCode.NotFound);
}
}
我该怎么办? Cr.marc_s编辑世界
答案 0 :(得分:0)
添加成员之前,您需要检查成员。当您尝试将成员添加到板卡时,Trello返回错误,但该成员已存在。反过来,这将导致Manatee.Trello引发异常。
此外,成员必须先属于董事会,然后才能分配给卡。
首先检查这些成员应该可以解决您的问题。
await Board.Memberships.Refresh(); // this will fetch all of the members of the board
foreach (string author in authors){
var Member = factory.Member(author);
if (!Board.Memberships.Any(m => m.Member == Member))
await Board.Memberships.Add(Member);
if (!Card.Members.Contains(Member))
await card.Members.Add(Member);
}
这应该可以解决您遇到的问题。
最后,当您捕获异常时,指定异常并可能打印或记录结果会很有帮助。 Trello非常擅长返回错误消息及其失败响应,而Manatee.Trello会将错误消息包含在其TrelloInteractionException
中。