namespace Application.Common.Models;
///
/// A standard response for service calls.
///
/// Return data type
public class ServiceResult : ServiceResult
{
public T? Data { get; set; }
public ServiceResult(T? data)
{
Data = data;
}
public ServiceResult(T? data, ServiceError error) : base(error)
{
Data = data;
}
public ServiceResult(ServiceError error) : base(error)
{
}
}
public class ServiceResult
{
public bool Succeeded => Error == null;
public ServiceError? Error { get; set; }
public ServiceResult(ServiceError? error)
{
error ??= ServiceError.DefaultError;
Error = error;
}
public ServiceResult() { }
#region Helper Methods
public static ServiceResult Failed(ServiceError error)
{
return new ServiceResult(error);
}
public static ServiceResult Failed(ServiceError error)
{
return new ServiceResult(error);
}
public static ServiceResult Failed(T data, ServiceError error)
{
return new ServiceResult(data, error);
}
public static ServiceResult Success(T data)
{
return new ServiceResult(data);
}
#endregion
}