WebApi统一输出接口

    public class WebApi
    {
        /// <summary>
        /// 成功后的输出
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static ResultDTO Success(object data)
        {
            //HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.OK;
            return new ResultDTO
            {
                status = true,
                info = data
            };
        }

        /// <summary>
        /// 失败后的输出
        /// </summary>
        /// <param name="islog"></param>
        /// <param name="exception"></param>
        /// <returns></returns>
        public static ResultDTO Error(object exception, bool islog = false)
        {
            //HttpContext.Current.Response.StatusCode = (int)WebApiException.GetHttpStatusByCode(exception);
            if (islog)
            {
                LogHelper.WriteLog(exception.ToString());
            }
            return new ResultDTO
            {
                status = false,
                info = exception.ToString()
            };
        }
    }

    /// <summary>
    /// 输出结果
    /// </summary>
    public class ResultDTO
    {
        public bool status; //状态
        public object info; //详情
    }

  

posted @ 2016-02-21 15:06  徐航  阅读(443)  评论(0编辑  收藏  举报