using System.Net;
namespace MaksIT.Results;
public partial class Result {
///
/// Returns a result indicating the request was successful and the server returned the requested data.
/// Corresponds to HTTP status code 200 OK.
///
public static Result Ok(string? message = null) =>
Ok(message != null ? [message] : null);
///
/// Returns a result indicating the request was successful and the server returned the requested data.
/// Corresponds to HTTP status code 200 OK.
///
public static Result Ok(List? messages = null) {
return new Result(true, messages ?? [], HttpStatusCode.OK);
}
///
/// Returns a result indicating the request was successful and a new resource was created.
/// Corresponds to HTTP status code 201 Created.
///
public static Result Created(string? message = null) =>
Created(message != null ? [message] : null);
///
/// Returns a result indicating the request was successful and a new resource was created.
/// Corresponds to HTTP status code 201 Created.
///
public static Result Created(List? messages = null) {
return new Result(true, messages ?? [], HttpStatusCode.Created);
}
///
/// Returns a result indicating the request has been accepted for processing, but the processing is not yet complete.
/// Corresponds to HTTP status code 202 Accepted.
///
public static Result Accepted(string? message = null) =>
Accepted(message != null ? [message] : null);
///
/// Returns a result indicating the request has been accepted for processing, but the processing is not yet complete.
/// Corresponds to HTTP status code 202 Accepted.
///
public static Result Accepted(List? messages = null) {
return new Result(true, messages ?? [], HttpStatusCode.Accepted);
}
///
/// Returns a result indicating the request was successful but the response contains metadata from a source other than the origin server.
/// Corresponds to HTTP status code 203 Non-Authoritative Information.
///
public static Result NonAuthoritativeInformation(string? message = null) =>
NonAuthoritativeInformation(message != null ? [message] : null);
///
/// Returns a result indicating the request was successful but the response contains metadata from a source other than the origin server.
/// Corresponds to HTTP status code 203 Non-Authoritative Information.
///
public static Result NonAuthoritativeInformation(List? messages = null) {
return new Result(true, messages ?? [], HttpStatusCode.NonAuthoritativeInformation);
}
///
/// Returns a result indicating the request was successful but there is no content to send in the response.
/// Corresponds to HTTP status code 204 No Content.
///
public static Result NoContent(string? message = null) =>
ResetContent(message != null ? [message] : null);
///
/// Returns a result indicating the request was successful but there is no content to send in the response.
/// Corresponds to HTTP status code 204 No Content.
///
public static Result NoContent(List? messages = null) {
return new Result(true, messages ?? [], HttpStatusCode.NoContent);
}
///
/// Returns a result indicating the request was successful, but the user-agent should reset the document view that caused the request.
/// Corresponds to HTTP status code 205 Reset Content.
///
public static Result ResetContent(string? message = null) =>
ResetContent(message != null ? [message] : null);
///
/// Returns a result indicating the request was successful, but the user-agent should reset the document view that caused the request.
/// Corresponds to HTTP status code 205 Reset Content.
///
public static Result ResetContent(List? messages = null) {
return new Result(true, messages ?? [], HttpStatusCode.ResetContent);
}
///
/// Returns a result indicating the request was successful and the server is delivering only part of the resource due to a range header sent by the client.
/// Corresponds to HTTP status code 206 Partial Content.
///
public static Result PartialContent(string? message = null) =>
PartialContent(message != null ? [message] : null);
///
/// Returns a result indicating the request was successful and the server is delivering only part of the resource due to a range header sent by the client.
/// Corresponds to HTTP status code 206 Partial Content.
///
public static Result PartialContent(List? messages = null) {
return new Result(true, messages ?? [], HttpStatusCode.PartialContent);
}
///
/// Returns a result indicating the request was successful and the response contains multiple status codes, typically used for WebDAV.
/// Corresponds to HTTP status code 207 Multi-Status.
///
public static Result MultiStatus(string? message = null) =>
MultiStatus(message != null ? [message] : null);
///
/// Returns a result indicating the request was successful and the response contains multiple status codes, typically used for WebDAV.
/// Corresponds to HTTP status code 207 Multi-Status.
///
public static Result MultiStatus(List? messages = null) {
return new Result(true, messages ?? [], HttpStatusCode.MultiStatus);
}
///
/// Returns a result indicating the request was successful and the information has already been reported in a previous response.
/// Corresponds to HTTP status code 208 Already Reported.
///
public static Result AlreadyReported(string? message = null) =>
AlreadyReported(message != null ? [message] : null);
///
/// Returns a result indicating the request was successful and the information has already been reported in a previous response.
/// Corresponds to HTTP status code 208 Already Reported.
///
public static Result AlreadyReported(List? messages = null) {
return new Result(true, messages ?? [], HttpStatusCode.AlreadyReported);
}
///
/// Returns a result indicating the request was successful and the server fulfilled the request for the resource using the delta encoding method.
/// Corresponds to HTTP status code 226 IM Used.
///
public static Result IMUsed(string? message = null) =>
IMUsed(message != null ? [message] : null);
///
/// Returns a result indicating the request was successful and the server fulfilled the request for the resource using the delta encoding method.
/// Corresponds to HTTP status code 226 IM Used.
///
public static Result IMUsed(List? messages = null) {
return new Result(true, messages ?? [], (HttpStatusCode)226); // 226 is the official status code for IM Used
}
}
public partial class Result : Result {
///
/// Returns a result indicating the request was successful and the server returned the requested data.
/// Corresponds to HTTP status code 200 OK.
///
public static Result Ok(T? value, string? message = null) =>
Ok(value, message != null ? [message] : null);
///
/// Returns a result indicating the request was successful and the server returned the requested data.
/// Corresponds to HTTP status code 200 OK.
///
public static Result Ok(T? value, List? messages = null) {
return new Result(value, true, messages ?? [], HttpStatusCode.OK);
}
///
/// Returns a result indicating the request was successful and a new resource was created.
/// Corresponds to HTTP status code 201 Created.
///
public static Result Created(T? value, string? message = null) =>
Created(value, message != null ? [message] : null);
///
/// Returns a result indicating the request was successful and a new resource was created.
/// Corresponds to HTTP status code 201 Created.
///
public static Result Created(T? value, List? messages = null) {
return new Result(value, true, messages ?? [], HttpStatusCode.Created);
}
///
/// Returns a result indicating the request has been accepted for processing, but the processing is not yet complete.
/// Corresponds to HTTP status code 202 Accepted.
///
public static Result Accepted(T? value, string? message = null) =>
Accepted(value, message != null ? [message] : null);
///
/// Returns a result indicating the request has been accepted for processing, but the processing is not yet complete.
/// Corresponds to HTTP status code 202 Accepted.
///
public static Result Accepted(T? value, List? messages = null) {
return new Result(value, true, messages ?? [], HttpStatusCode.Accepted);
}
///
/// Returns a result indicating the request was successful but the response contains metadata from a source other than the origin server.
/// Corresponds to HTTP status code 203 Non-Authoritative Information.
///
public static Result NonAuthoritativeInformation(T? value, string? message = null) =>
NonAuthoritativeInformation(value, message != null ? [message] : null);
///
/// Returns a result indicating the request was successful but the response contains metadata from a source other than the origin server.
/// Corresponds to HTTP status code 203 Non-Authoritative Information.
///
public static Result NonAuthoritativeInformation(T? value, List? messages = null) {
return new Result(value, true, messages ?? [], HttpStatusCode.NonAuthoritativeInformation);
}
///
/// Returns a result indicating the request was successful but there is no content to send in the response.
/// Corresponds to HTTP status code 204 No Content.
///
public static Result NoContent(T? value, string? message = null) =>
NoContent(value, message != null ? [message] : null);
///
/// Returns a result indicating the request was successful but there is no content to send in the response.
/// Corresponds to HTTP status code 204 No Content.
///
public static Result NoContent(T? value, List? messages = null) {
return new Result(value, true, messages ?? [], HttpStatusCode.NoContent);
}
///
/// Returns a result indicating the request was successful, but the user-agent should reset the document view that caused the request.
/// Corresponds to HTTP status code 205 Reset Content.
///
public static Result ResetContent(T? value, string? message = null) =>
ResetContent(value, message != null ? [message] : null);
///
/// Returns a result indicating the request was successful, but the user-agent should reset the document view that caused the request.
/// Corresponds to HTTP status code 205 Reset Content.
///
public static Result ResetContent(T? value, List? messages = null) {
return new Result(value, true, messages ?? [], HttpStatusCode.ResetContent);
}
///
/// Returns a result indicating the request was successful and the server is delivering only part of the resource due to a range header sent by the client.
/// Corresponds to HTTP status code 206 Partial Content.
///
public static Result PartialContent(T? value, string? message = null) =>
PartialContent(value, message != null ? [message] : null);
///
/// Returns a result indicating the request was successful and the server is delivering only part of the resource due to a range header sent by the client.
/// Corresponds to HTTP status code 206 Partial Content.
///
public static Result PartialContent(T? value, List? messages = null) {
return new Result(value, true, messages ?? [], HttpStatusCode.PartialContent);
}
///
/// Returns a result indicating the request was successful and the response contains multiple status codes, typically used for WebDAV.
/// Corresponds to HTTP status code 207 Multi-Status.
///
public static Result MultiStatus(T? value, string? message = null) =>
MultiStatus(value, message != null ? [message] : null);
///
/// Returns a result indicating the request was successful and the response contains multiple status codes, typically used for WebDAV.
/// Corresponds to HTTP status code 207 Multi-Status.
///
public static Result MultiStatus(T? value, List? messages = null) {
return new Result(value, true, messages ?? [], HttpStatusCode.MultiStatus);
}
///
/// Returns a result indicating the request was successful and the information has already been reported in a previous response.
/// Corresponds to HTTP status code 208 Already Reported.
///
public static Result AlreadyReported(T? value, string? message = null) =>
AlreadyReported(value, message != null ? [message] : null);
///
/// Returns a result indicating the request was successful and the information has already been reported in a previous response.
/// Corresponds to HTTP status code 208 Already Reported.
///
public static Result AlreadyReported(T? value, List? messages = null) {
return new Result(value, true, messages ?? [], HttpStatusCode.AlreadyReported);
}
///
/// Returns a result indicating the request was successful and the server fulfilled the request for the resource using the delta encoding method.
/// Corresponds to HTTP status code 226 IM Used.
///
public static Result IMUsed(T? value, string? message = null) =>
IMUsed(value, message != null ? [message] : null);
///
/// Returns a result indicating the request was successful and the server fulfilled the request for the resource using the delta encoding method.
/// Corresponds to HTTP status code 226 IM Used.
///
public static Result IMUsed(T? value, List? messages = null) {
return new Result(value, true, messages ?? [], (HttpStatusCode)226); // 226 is the official status code for IM Used
}
}