namespace Dpz.Core.Public.ViewModel;
#nullable enable
public class ResponseResult
{
/// <summary>
/// 是否成功
/// </summary>
public bool Success { get; set; }
/// <summary>
/// 消息
/// </summary>
public string? Message { get; set; }
/// <summary>
/// 状态码
/// </summary>
public int Code { get; set; }
public static ResponseResult ToSuccess() => new() { Success = true };
public static ResponseResult ToFail(string message, int code = 1) =>
new()
{
Success = false,
Message = message,
Code = code,
};
}
public class ResponseResult<T> : ResponseResult
{
public T? Data { get; set; }
public ResponseResult<T> SuccessResult(T? data) => new() { Success = true, Data = data };
public ResponseResult<T> FailResult(string message, int code = 1) =>
new()
{
Success = false,
Message = message,
Code = code,
Data = default,
};
public static ResponseResult<T> ToSuccess(T? data) => new() { Success = true, Data = data };
public new static ResponseResult<T> ToFail(string message, int code = 1) =>
new()
{
Success = false,
Message = message,
Code = code,
Data = default,
};
}