YD_YiLu.Api/YD_YiLu.Commons/Dto/WebResponseContent.cs

80 lines
2.2 KiB
C#
Raw Normal View History

2026-04-08 16:09:51 +08:00
namespace YD_YiLu.Commons.Dto
2026-03-04 09:05:31 +08:00
{
public class WebResponseContent
{
public WebResponseContent()
{
}
public WebResponseContent(bool Success)
{
2026-03-27 10:53:02 +08:00
this.Code = 0;
this.Msg = "OK";
2026-03-04 09:05:31 +08:00
}
2026-03-27 10:53:02 +08:00
public int Code { get; set; }
public string Msg { get; set; }
2026-03-04 09:05:31 +08:00
public object Data { get; set; }
public WebResponseContent OK()
{
2026-03-27 10:53:02 +08:00
this.Code = 0;
this.Msg = "OK";
2026-03-04 09:05:31 +08:00
return this;
}
public static WebResponseContent Instance
{
get { return new WebResponseContent(); }
}
2026-03-27 10:53:02 +08:00
public WebResponseContent OK(string ErrorMsg = null, object data = null)
2026-03-04 09:05:31 +08:00
{
2026-03-27 10:53:02 +08:00
this.Code = 0;
this.Msg = ErrorMsg;
2026-03-04 09:05:31 +08:00
this.Data = data;
return this;
}
public WebResponseContent OK(ResponseType responseType)
{
return Set(responseType, true);
}
public WebResponseContent Error(string ErrorMsg = null)
{
2026-03-27 10:53:02 +08:00
this.Code = 0;
this.Msg = ErrorMsg;
2026-03-04 09:05:31 +08:00
return this;
}
public WebResponseContent Error(ResponseType responseType)
{
return Set(responseType, false);
}
public WebResponseContent Set(ResponseType responseType)
{
bool? b = null;
return this.Set(responseType, b);
}
public WebResponseContent Set(ResponseType responseType, bool? Success)
{
return this.Set(responseType, null, Success);
}
public WebResponseContent Set(ResponseType responseType, string msg)
{
2026-03-27 10:53:02 +08:00
return this.Set(responseType, msg,true);
2026-03-04 09:05:31 +08:00
}
public WebResponseContent Set(ResponseType responseType, string msg, bool? Success)
{
if (Success != null)
{
2026-03-27 10:53:02 +08:00
this.Code = 0;
this.Msg = "OK";
2026-03-04 09:05:31 +08:00
}
2026-03-27 10:53:02 +08:00
this.Msg = ((int)responseType).ToString();
2026-03-04 09:05:31 +08:00
if (!string.IsNullOrEmpty(msg))
{
2026-03-27 10:53:02 +08:00
Msg = msg;
2026-03-04 09:05:31 +08:00
return this;
}
2026-03-27 10:53:02 +08:00
Msg = responseType.GetMsg();
2026-03-04 09:05:31 +08:00
return this;
}
}
}