• C#标准响应数据


     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;
            }
        }
    

      

  • 相关阅读:
    java设计模式演示样例
    一步一步写算法(之排序二叉树)
    收集经常使用的.net开源项目
    jdbc连接数据库
    Android开发系列(二十二):AdapterViewFlipper的功能和使用方法
    ProgressDialog使用总结
    HDU 4916 树分治
    [Unity3D]自制UnityForAndroid二维码扫描插件
    IOS ARC和非ARC文件混用
    让子弹飞Demo版
  • 原文地址:https://www.cnblogs.com/yzenet/p/5619156.html
Copyright © 2020-2023  润新知