using System; using System.Collections.Generic; using System.Net; using System.Text; namespace Appointment.Entity { /// /// 接口返回数据标准 /// public class ApiResult { /// /// 响应状态:true-成功执行,flase-响应异常 /// public bool IsSuccess { get { return this.Code == (int)HttpStatusCode.OK; } } /// /// 是否有效执行以IsSuccess为基准 /// 200-有效执行,500-服务错误 /// /// /// 此属性为定制化返回代码,例如登录成功并需要返回提示修改密码等相关类似的业务 /// public int Code { get; set; } /// /// 返回消息文本内容 /// public string Msg { get; set; } /// /// 返回数据 /// public object Info { get; set; } /// /// 构造函数 /// /// /// /// public ApiResult(int code = (int)HttpStatusCode.OK, string msg = "操作成功", object info = null) { this.Code = code; this.Msg = msg; this.Info = info; } /// /// 成功执行 /// /// /// /// public static ApiResult Success(string msg = "操作成功", object info = null) { return new ApiResult { Code = (int)HttpStatusCode.OK, Msg = msg, Info = info, }; } /// /// 执行错误 /// /// /// /// /// public static ApiResult Failed(string msg = "操作失败", object info = null, int code = (int)HttpStatusCode.InternalServerError) { return new ApiResult { Code = code, Msg = msg, Info = info, }; } } /// /// 接口返回数据标准 /// /// public class ApiResult { /// /// 响应状态:true-成功执行,flase-响应异常 /// public bool IsSuccess { get { return this.Code == (int)HttpStatusCode.OK; } } /// /// 是否有效执行以IsSuccess为基准 /// 200-有效执行,500-服务错误 /// /// /// 此属性为定制化返回代码,例如登录成功并需要返回提示修改密码等相关类似的业务 /// public int Code { get; set; } /// /// 返回消息文本内容 /// public string Msg { get; set; } /// /// 返回数据 /// public T Info { get; set; } /// /// 构造函数 /// /// /// /// public ApiResult(int code = (int)HttpStatusCode.OK, string msg = "操作成功", T info = default) { this.Code = code; this.Msg = msg; this.Info = info; } /// /// 执行成功 /// /// /// /// public static ApiResult Success(string msg = "操作成功", T info = default) { return new ApiResult { Code = (int)HttpStatusCode.OK, Msg = msg, Info = info, }; } /// /// 出现错误 /// /// /// /// /// public static ApiResult Failed(string msg = "操作失败", int code = (int)HttpStatusCode.InternalServerError, T info = default) { return new ApiResult { Code = code, Msg = msg, Info = info, }; } } /// /// 公共Msg /// public class ApiResultMsg { /// /// 参数无效 /// public string InvalidParameter { get { return $"参数[{_InvalidParameter}]无效!"; } set { _InvalidParameter = value; } } private string _InvalidParameter; /// /// 缺少参数 /// public static string NoParameter { get { return "缺少参数!"; } } /// /// 没有权限 /// public static string NoPower { get { return "没有权限,操作失败!"; } } /// /// 没有数据 /// public static string NoData { get { return "没有数据!"; } } /// /// 数据不正确 /// public static string ErrorData { get { return "数据不正确!"; } } } }