예제 #1
0
    public static string SaveRQMTChanges(string changes)
    {
        var result = WTSPage.CreateDefaultResult();

        try
        {
            JObject jobj = (JObject)JsonConvert.DeserializeObject(changes);

            int    RQMTID         = 0;
            string addToSets      = "";
            string deleteFromSets = "";
            string RQMTText       = "";

            foreach (KeyValuePair <string, JToken> token in (JObject)jobj)
            {
                string value = token.Value.ToString();

                if (token.Key == "RQMTID")
                {
                    RQMTID = Int32.Parse(value);
                }
                else if (token.Key == "adds")
                {
                    addToSets = value;
                }
                else if (token.Key == "deletes")
                {
                    deleteFromSets = value;
                }
                else if (token.Key == "RQMT")
                {
                    RQMTText = value;
                }
            }

            int returnID = RQMT.RQMTBuilder_RQMTUpdate(RQMTID, RQMTText, addToSets, deleteFromSets);

            if (returnID != RQMTID)
            {
                result["error"] = "Change cannot be saved. Another RQMT already exists with the same text (RQMT #" + returnID + ").";
            }
            else
            {
                result["success"] = "true";
            }
        }
        catch (Exception e)
        {
            result["error"] = e.Message;
        }

        return(WTSPage.SerializeResult(result));
    }