Exemplo n.º 1
0
    public static string SaveWorkRequest(object workRequest)
    {
        Dictionary <string, string> result = new Dictionary <string, string>()
        {
            { "saved", "" }, { "id", "0" }, { "error", "" }
        };
        bool   saved    = false;
        int    id       = 0;
        string errorMsg = string.Empty;

        Dictionary <string, object> attributeList;

        if (workRequest == null)
        {
            saved    = false;
            errorMsg = "No Work Request details were found.";
        }
        else
        {
            try
            {
                attributeList = (Dictionary <string, object>)workRequest;

                WorkRequest request = new WorkRequest(attributeList);

                if (request.WORKREQUESTID == 0)                 //save new item
                {
                    int newID = 0;
                    saved = WorkRequest.WorkRequest_Add(request, out newID, out errorMsg);
                    id    = newID;
                }
                else                 //update existing item
                {
                    id    = request.WORKREQUESTID;
                    saved = WorkRequest.WorkRequest_Update(request, out errorMsg);
                }
            }
            catch (Exception ex)
            {
                saved    = false;
                errorMsg = ex.Message;
                LogUtility.LogException(ex);
            }
        }

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

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