44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using System.Text.Json.Serialization;
|
|
|
|
namespace DigitalData.Core.DTO
|
|
{
|
|
public class Result
|
|
{
|
|
public bool IsSuccess { get; set; } = false;
|
|
|
|
public List<string> Messages { get; init; } = new();
|
|
|
|
[JsonIgnore]
|
|
public List<Notice> Notices = new();
|
|
|
|
public DataResult<T> Data<T>(T data) => new()
|
|
{
|
|
IsSuccess = IsSuccess,
|
|
Messages = Messages,
|
|
Notices = Notices,
|
|
Data = data
|
|
};
|
|
|
|
public bool HasFlag(Enum flag) => Notices.Any(n => n.Flag?.ToString() == flag.ToString());
|
|
|
|
public bool HasAnyFlag(params Enum[] flags) => flags.Any(f => HasFlag(f));
|
|
|
|
public static Result Success() => new() { IsSuccess = true };
|
|
|
|
public static Result Fail() => new() { IsSuccess = false };
|
|
|
|
public static DataResult<T> Success<T>(T data) => new()
|
|
{
|
|
IsSuccess = true,
|
|
Data = data
|
|
};
|
|
|
|
#pragma warning disable CS8601 // Possible null reference assignment.
|
|
public static DataResult<T> Fail<T>() => new()
|
|
{
|
|
IsSuccess = false,
|
|
Data = default
|
|
};
|
|
#pragma warning restore CS8601 // Possible null reference assignment.
|
|
}
|
|
} |