public HttpResponseMessage UpdateModule(Mode mode)
{
var response = Process.Instance.ExecuteString(() =>
{
var count = DbHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), parms);
if (count < 0)
{
resultMsg.ResultMsg = "更新失败";
return resultMsg.ToJson();
}
resultMsg.Result = 1;
resultMsg.total = 1;
resultMsg.ResultMsg = "更新成功";
return resultMsg.ToJson();
});
return HttpHelper.ResponseMessagetoJson(response);
}
public class Process
{
private static volatile Process _process = null;
private readonly string returnMsg = "{\"RowsCount\":0,\"Result\":-1,\"ResultMsg\":\" api 500 error\",\"Rows\":null}";
protected Process()
{
}
/// <summary> Gets the instance
/// </summary>
public static Process Instance
{
get
{
if (_process == null)
{
lock (typeof(Process))
{
if (_process == null)
{
_process = new Process();
}
}
}
return _process;
}
}
public string ExecuteString(Func<string> action)
{
try
{
return action.Invoke();
}
catch (Exception ex)
{
Logger.Error(ex);
return returnMsg;
}
}
public dynamic ExecuteStringExtend(Func<dynamic> action)
{
try
{
return action.Invoke();
}
catch (Exception ex)
{
Logger.Error(ex);
return returnMsg;
}
}
public string ExecuteStringtran(Func<string> action,ITransactionManager tran)
{
try
{
return action.Invoke();
}
catch (Exception ex)
{
Logger.Error(ex);
if (tran != null) tran.Rollback();
return returnMsg;
}
}
}
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 StringContent(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;
}
}