Publichttpresponsemessage updatemodule (mode mode) {varResponse = Process.Instance.ExecuteString (() = { varCount =dbhelper.executenonquery (CommandType.Text, strsql.tostring (), parms); if(Count <0) {resultmsg.resultmsg="Update failed"; returnResultmsg.tojson (); } Resultmsg.result=1; Resultmsg.total=1; Resultmsg.resultmsg="Update Successful"; returnResultmsg.tojson (); }); returnHttphelper.responsemessagetojson (response); }
Public classProcess {Private Static volatileProcess _process =NULL; Private ReadOnly stringReturnmsg ="{\ "rowscount\": 0,\ "result\": -1,\ "resultmsg\": \ "API error\", \ "rows\": null}"; protectedProcess () {}/// <summary>Gets The instance/// </summary> Public StaticProcess Instance {Get { if(_process = =NULL) { Lock(typeof(Process)) { if(_process = =NULL) {_process=NewProcess (); } } } return_process; } } Public stringExecutestring (func<string>action) { Try { returnaction. Invoke (); } Catch(Exception ex) {logger.error (ex); returnreturnmsg; } } Public DynamicExecutestringextend (func<Dynamic>action) { Try { returnaction. Invoke (); } Catch(Exception ex) {logger.error (ex); returnreturnmsg; } } Public stringExecutestringtran (func<string>Action,itransactionmanager Tran) { Try { returnaction. Invoke (); } Catch(Exception ex) {logger.error (ex); if(Tran! =NULL) Tran. Rollback (); returnreturnmsg; } } }
public static class Httphelper {public static httpresponsemessage Responsemessagetojsonextnd (String str) {var response = new Httpresponsemessage (Httpstatuscode.ok); Httpcontent content = Response. Content; Response. Content = new Stringcontent (str, encoding.getencoding ("UTF-8"), "text/html"); return response; } public static Httpresponsemessage Responsemessagetojson (Object obj) {string str; if ((obj is string) | | (obj is char)) {str = obj. ToString (); } else {str = obj. ToJson (); } var response = new Httpresponsemessage (httpstatuscode.ok) {Content = new Stringcon Tent (str, encoding.getencoding ("UTF-8"), "text/html")}; return response; } public static Httpresponsemessage Responsemessagetojsonextend (String str) { var response = new Httpresponsemessage (httpstatuscode.ok) {Content = new stringcontent (str, Encoding.GetEncoding ("UTF-8"), "text/html")}; return response; } }
C # Standard response data