This commit is contained in:
thepra committed 2023-02-19 00:43:43 +01:00
1 parent 9719a0c0fd
commit 1e66851113
146 files changed
+738 -382

No files matched your search

+59
View File
@@ -0,0 +1,59 @@
using System.Net;
using System.Text.Json.Serialization;
namespace PrivaPub.ClientModels
{
public class WebResult
{
public WebResult Invalidate<T>(string errorMessage,
int statusCode = (int)HttpStatusCode.BadRequest,
string errorCode = "4000",
Exception exception = null,
T defaultData = default)
{
IsValid = false;
ErrorMessage += errorMessage;
StatusCode = statusCode;
ErrorCode = errorCode;
Exception = exception;
Data = defaultData;
return this;
}
public WebResult Invalidate(string errorMessage,
int statusCode = (int)HttpStatusCode.BadRequest,
string errorCode = "4000",
Exception exception = null)
{
IsValid = false;
ErrorMessage += errorMessage;
StatusCode = statusCode;
ErrorCode = errorCode;
Exception = exception;
return this;
}
public WebResult Invalidate(WebResult result)
{
IsValid = result.IsValid;
ErrorMessage += result.ErrorMessage;
StatusCode = result.StatusCode;
ErrorCode = result.ErrorCode;
Exception = result.Exception;
Data = result.Data;
return this;
}
public string ErrorCode { get; set; } = "0000";
public int StatusCode { get; set; } = (int)HttpStatusCode.OK;
public string ErrorMessage { get; set; }
public bool IsValid { get; set; } = true;
[JsonIgnore]
public object Data { get; set; }
[JsonIgnore]
public Exception Exception { get; set; }
}
}