80 lines
1.8 KiB
C#
80 lines
1.8 KiB
C#
using YD_XinWei.Commons.Enum;
|
|
|
|
namespace YD_XinWei.Commons.Dto
|
|
{
|
|
public class WebResponseContent
|
|
{
|
|
private string _errorMsg = "";
|
|
|
|
public bool Success { get; set; }
|
|
|
|
public string ErrorCode { get; set; } = "";
|
|
|
|
public string ErrorMsg
|
|
{
|
|
get => _errorMsg;
|
|
set => _errorMsg = value ?? "";
|
|
}
|
|
|
|
public object Data { get; set; }
|
|
|
|
public WebResponseContent()
|
|
{
|
|
ErrorMsg = "";
|
|
}
|
|
|
|
public WebResponseContent(bool success)
|
|
{
|
|
Success = success;
|
|
ErrorMsg = "";
|
|
}
|
|
|
|
public static WebResponseContent Instance => new WebResponseContent();
|
|
|
|
public WebResponseContent OK(object data = null, string msg = "")
|
|
{
|
|
Success = true;
|
|
Data = data;
|
|
ErrorMsg = msg ?? "";
|
|
return this;
|
|
}
|
|
|
|
public WebResponseContent OK(ResponseType type)
|
|
{
|
|
return Set(type, null, true);
|
|
}
|
|
|
|
public WebResponseContent Error(string msg = "")
|
|
{
|
|
Success = false;
|
|
ErrorMsg = msg ?? "";
|
|
return this;
|
|
}
|
|
|
|
public WebResponseContent Error(ResponseType type)
|
|
{
|
|
return Set(type, null, false);
|
|
}
|
|
|
|
public WebResponseContent Set(ResponseType type, string msg = null, bool? success = null)
|
|
{
|
|
if (success.HasValue)
|
|
{
|
|
Success = success.Value;
|
|
}
|
|
|
|
ErrorCode = ((int)type).ToString();
|
|
|
|
if (!string.IsNullOrEmpty(msg))
|
|
{
|
|
ErrorMsg = msg;
|
|
}
|
|
else
|
|
{
|
|
ErrorMsg = type.GetMsg() ?? "";
|
|
}
|
|
|
|
return this;
|
|
}
|
|
}
|
|
} |