Esempio n. 1
0
    public static string SaveComments(int workItemID, dynamic comments)
    {
        Dictionary <string, string> result = new Dictionary <string, string>()
        {
            { "saved", "" }, { "ids", "" }, { "error", "" }
        };

        bool   saved = false;
        string errorMsg = string.Empty, ids = string.Empty;
        int    commentId = 0, parentCommentId = 0;
        string commentText = string.Empty;

        foreach (dynamic comment in comments)
        {
            commentId       = 0;
            parentCommentId = 0;
            //comment[0]=commentid, comment[1]=parentid, comment[2]=text
            try
            {
                commentText = comment[2].ToString();
                if (string.IsNullOrWhiteSpace(comment[0].ToString()) ||
                    !int.TryParse(comment[0].ToString(), out commentId))
                {
                    int.TryParse(comment[1].ToString(), out parentCommentId);
                    saved = WorkloadItem.WorkItem_Comment_Add(out commentId, out errorMsg, workItemID, parentCommentId, commentText);
                }
                else
                {
                    saved = WorkloadItem.WorkItem_Comment_Update(out errorMsg, commentId, commentText);
                }


                if (saved)
                {
                    ids += commentId.ToString() + ",";
                }
            }
            catch (Exception ex)
            {
                LogUtility.LogException(ex);
                errorMsg += ": " + ex.Message;
            }
        }

        ids = ids.TrimEnd(new char[] { ',' });
        if (ids.Length > 0)
        {
            saved = true;
            Workload.SendWorkloadEmail("WorkItem", false, workItemID);
        }

        result["saved"] = saved.ToString();
        result["ids"]   = ids;
        result["error"] = errorMsg;

        return(JsonConvert.SerializeObject(result, Formatting.None));
    }