Infrastructure/OpenAuth.App/ServiceApp/GoView/Response/AjaxResult.cs

92 lines
1.8 KiB
C#

namespace OpenAuth.App.ServiceApp.GoView.Response;
public class AjaxResult : Dictionary<string, object>
{
/**
* 初始化一个新创建的 Message 对象
*/
public AjaxResult()
{
}
/**
* 返回错误消息
*
* @return 错误消息
*/
public static AjaxResult Error()
{
return Error(500, "操作失败");
}
/**
* 返回错误消息
*
* @param msg 内容
* @return 错误消息
*/
public static AjaxResult Error(string msg)
{
return Error(500, msg);
}
/**
* 返回错误消息
*
* @param code 错误码
* @param msg 内容
* @return 错误消息
*/
public static AjaxResult Error(int code, string msg)
{
AjaxResult json = new AjaxResult();
json["code"] = code;
json["msg"] = msg;
return json;
}
/**
* 返回成功消息
*
* @param msg 内容
* @return 成功消息
*/
public static AjaxResult Success(string msg)
{
AjaxResult json = new AjaxResult();
json["msg"] = msg;
json["code"] = 200;
return json;
}
/**
* 返回成功消息
*
* @return 成功消息
*/
public static AjaxResult Success()
{
return Success("操作成功");
}
public static AjaxResult SuccessData(int code, object value)
{
AjaxResult json = new AjaxResult();
json["code"] = code;
json["data"] = value;
return json;
}
/**
* 返回成功消息
*
* @param key 键值
* @param value 内容
* @return 成功消息
*/
public new AjaxResult Put(string key, object value)
{
base[key] = value;
return this;
}
}