博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#标准响应数据
阅读量:6479 次
发布时间:2019-06-23

本文共 3565 字,大约阅读时间需要 11 分钟。

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()        {        }        ///  Gets the instance        ///         public static Process Instance        {            get            {                if (_process == null)                {                    lock (typeof(Process))                    {                        if (_process == null)                        {                            _process = new Process();                        }                    }                }                return _process;            }        }        public string ExecuteString(Func
action) { try { return action.Invoke(); } catch (Exception ex) { Logger.Error(ex); return returnMsg; } } public dynamic ExecuteStringExtend(Func
action) { try { return action.Invoke(); } catch (Exception ex) { Logger.Error(ex); return returnMsg; } } public string ExecuteStringtran(Func
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;        }    }

  

转载地址:http://bkwuo.baihongyu.com/

你可能感兴趣的文章
HDU 5167 Fibonacci(BestCoder Round #28)
查看>>
给定中序和后序遍历,求前序序列(C++递归方式实现)
查看>>
将菜单栏放在应用程序内
查看>>
Cenos7 部署asp.net core站点
查看>>
html5摇一摇[转]
查看>>
彻底理解ThreadLocal
查看>>
Hello
查看>>
中国工业软件成立联盟合力对外
查看>>
面向的对象编程的小猫腻
查看>>
第二课:基本电路法
查看>>
【转】C# DateTime 日期计算
查看>>
${ } 的一些用法
查看>>
团队开发冲刺第二阶段6
查看>>
rpm的含义
查看>>
iis伪静态写法
查看>>
洛谷P1379 八数码难题
查看>>
POJ 3734 生成函数
查看>>
Spring Web MVC
查看>>
Web Deploy发布网站错误 检查授权和委派设置
查看>>
【文文殿下】WC2019游记
查看>>