public static string DeleteComments(int workItemID, dynamic arrCommentIDsToDelete) { Dictionary <string, string> result = new Dictionary <string, string>() { { "deleted", "" }, { "ids", "" }, { "error", "" } }; bool deleted = false; string errorMsg = string.Empty, ids = string.Empty; int commentId = 0; foreach (dynamic id in arrCommentIDsToDelete) { commentId = 0; try { if (int.TryParse(id.ToString(), out commentId)) { deleted = WorkloadItem.WorkItem_Comment_Delete(out errorMsg, workItemID, commentId); if (deleted) { ids += "," + commentId.ToString(); } } } catch (Exception ex) { LogUtility.LogException(ex); errorMsg += ": " + ex.Message; deleted = false; } } ids = ids.TrimEnd(new char[] { ',' }); if (ids.Length > 0) { deleted = true; } result["deleted"] = deleted.ToString(); result["ids"] = ids; result["error"] = errorMsg; return(JsonConvert.SerializeObject(result, Formatting.None)); }