You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
2.8 KiB
C#
100 lines
2.8 KiB
C#
using VOL.Core.Enums;
|
|
using VOL.Core.Extensions;
|
|
using VOL.Core.Services;
|
|
|
|
namespace VOL.Core.Utilities
|
|
{
|
|
public class WebResponseContent
|
|
{
|
|
public WebResponseContent()
|
|
{
|
|
}
|
|
public WebResponseContent(bool status)
|
|
{
|
|
this.Status = status;
|
|
}
|
|
public bool Status { get; set; }
|
|
public string Code { get; set; }
|
|
public string Message { get; set; }
|
|
//public string Message { get; set; }
|
|
public object Data { get; set; }
|
|
|
|
public WebResponseContent OK()
|
|
{
|
|
this.Status = true;
|
|
return this;
|
|
}
|
|
|
|
public static WebResponseContent Instance
|
|
{
|
|
get { return new WebResponseContent(); }
|
|
}
|
|
public WebResponseContent OK(string message = null,object data=null)
|
|
{
|
|
this.Status = true;
|
|
this.Message = message;
|
|
this.Data = data;
|
|
return this;
|
|
}
|
|
public WebResponseContent OK(ResponseType responseType)
|
|
{
|
|
return Set(responseType, true);
|
|
}
|
|
public WebResponseContent Error(string message = null)
|
|
{
|
|
this.Status = false;
|
|
this.Message = message;
|
|
return this;
|
|
}
|
|
public WebResponseContent Error(ResponseType responseType)
|
|
{
|
|
return Set(responseType, false);
|
|
}
|
|
|
|
public WebResponseContent Error_Data(object data,string message = null)
|
|
{
|
|
this.Status = false;
|
|
this.Message = message;
|
|
this.Data = data;
|
|
return this;
|
|
}
|
|
public WebResponseContent Set(ResponseType responseType)
|
|
{
|
|
bool? b = null;
|
|
return this.Set(responseType, b);
|
|
}
|
|
public WebResponseContent Set(ResponseType responseType, bool? status)
|
|
{
|
|
return this.Set(responseType, null, status);
|
|
}
|
|
public WebResponseContent Set(ResponseType responseType, string msg)
|
|
{
|
|
bool? b = null;
|
|
return this.Set(responseType, msg, b);
|
|
}
|
|
public WebResponseContent Set(ResponseType responseType, string msg, bool? status)
|
|
{
|
|
if (status != null)
|
|
{
|
|
this.Status = (bool)status;
|
|
}
|
|
this.Code = ((int)responseType).ToString();
|
|
if (!string.IsNullOrEmpty(msg))
|
|
{
|
|
Message = msg;
|
|
return this;
|
|
}
|
|
Message = responseType.GetMsg();
|
|
return this;
|
|
}
|
|
public WebResponseContent SaveAndError(string message = null)
|
|
{
|
|
Logger.Error($"错误:{message}");
|
|
this.Status = false;
|
|
this.Message = message;
|
|
return this;
|
|
}
|
|
|
|
}
|
|
}
|