using System.Net; namespace MaksIT.Results; public partial class Result { #region Common Success Responses /// /// 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(params string[] messages) { 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(params string[] messages) { 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(params string[] messages) { 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(params string[] messages) { 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(params string[] messages) { 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(params string[] messages) { 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(params string[] messages) { return new Result(true, [..messages], HttpStatusCode.PartialContent); } #endregion #region Extended Or Less Common Success Responses /// /// 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(params string[] messages) { 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(params string[] messages) { 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(params string[] messages) { return new Result(true, [..messages], (HttpStatusCode)226); // 226 is the official status code for IM Used } #endregion } public partial class Result : Result { #region Common Success Responses /// /// 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, params string[] messages) { 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, params string[] messages) { 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, params string[] messages) { 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, params string[] messages) { 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, params string[] messages) { 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, params string[] messages) { 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, params string[] messages) { return new Result(value, true, [..messages], HttpStatusCode.PartialContent); } #endregion #region Extended Or Less Common Success Responses /// /// 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, params string[] messages) { 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, params string[] messages) { 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, params string[] messages) { return new Result(value, true, [..messages], (HttpStatusCode)226); // 226 is the official status code for IM Used } #endregion }