SocialPub/SocialPub.ClientModels/WebResult.cs

60 lines
1.4 KiB
C#
Raw Normal View History

2023-02-18 08:52:17 +01:00
using System.Net;
using System.Text.Json.Serialization;
namespace SocialPub.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; }
}
}