// Aliases for DomainResult<TValue> extensions [PUBLIC, STATIC] #region Extensions of 'IDomainResult<T>' [STATIC, PUBLIC] ------------- /// <summary> /// Get 'success' status with a value. Gets converted to HTTP code 200 (Ok) /// </summary> /// <typeparam name="TValue"> The value type </typeparam> /// <param name="value"> The value to be returned </param> public static IDomainResult <TValue> Success <TValue>(TValue value) => DomainResult <TValue> .Success(value);
/// <summary> /// Get 'not found' status. Gets converted to HTTP code 404 (NotFound) /// </summary> /// <typeparam name="TValue"> The expected value type if the operation was successful </typeparam> /// <param name="message"> Optional message </param> public static IDomainResult <TValue> NotFound <TValue>(string?message = null) => DomainResult <TValue> .NotFound(message);
/// <summary> /// Get 'Unauthorized' status wrapped in a <see cref="Task{T}"/>. Gets converted to HTTP code 403 (Forbidden) /// </summary> /// <typeparam name="TValue"> The expected value type if the operation was successful </typeparam> /// <param name="message"> Optional message </param> public static Task <IDomainResult <TValue> > UnauthorizedTask <TValue>(string?message = null) => DomainResult <TValue> .UnauthorizedTask(message);
/// <summary> /// Get 'error' status. Gets be converted to HTTP code 400/422 /// </summary> /// <param name="error"> Optional message </param> public static IDomainResult <TValue> Failed(string?error = null) => new DomainResult <TValue>(DomainResult.Failed(error));
/// <summary> /// Get 'error' status with validation errors. Gets converted to HTTP code 400/422 /// </summary> /// <typeparam name="TValue"> The expected value type if the operation was successful </typeparam> /// <param name="validationResults"> Results of a validation request </param> public static IDomainResult <TValue> Failed <TValue>(IEnumerable <ValidationResult> validationResults) => DomainResult <TValue> .Failed(validationResults);
/// <summary> /// Get 'not found' status wrapped in a <see cref="Task{T}"/>. Gets converted to HTTP code 404 (NotFound) /// </summary> /// <typeparam name="TValue"> The expected value type if the operation was successful </typeparam> /// <param name="message"> Optional message </param> public static Task <IDomainResult <TValue> > NotFoundTask <TValue>(string?message = null) => DomainResult <TValue> .NotFoundTask(message);
/// <summary> /// Convert to <see cref="IDomainResult{T}" /> (the domain operation result with a returned value) /// </summary> /// <typeparam name="T"> Value type of returned by the domain operation </typeparam> public static IDomainResult <T> To <T>(this IDomainResult domainResult) { return(DomainResult <T> .From(domainResult)); }
/// <summary> /// Get 'error' status. Gets converted to HTTP code 400/422 /// </summary> /// <typeparam name="TValue"> The expected value type if the operation was successful </typeparam> /// <param name="error"> Optional message </param> public static IDomainResult <TValue> Failed <TValue>(string?error = null) => DomainResult <TValue> .Failed(error);
/// <summary> /// Get 'not found' status. Gets converted to HTTP code 404 (NotFound) /// </summary> /// <param name="message"> Optional message </param> public static IDomainResult <TValue> NotFound(string?message = null) => new DomainResult <TValue>(DomainResult.NotFound(message));
/// <summary> /// Get 'not found' status. Gets converted to HTTP code 404 (NotFound) /// </summary> /// <param name="messages"> Custom messages </param> public static IDomainResult <TValue> NotFound(IEnumerable <string> messages) => new DomainResult <TValue>(DomainResult.NotFound(messages));
/// <summary> /// Creates a new instance with 'success' status and a value /// </summary> /// <param name="value"> The value to be returned </param> protected DomainResult(TValue value) : this(value, DomainResult.Success()) { }
/// <summary> /// Get 'error' status with validation errors. Gets be converted to HTTP code 400/422 /// </summary> /// <param name="validationResults"> Results of a validation request </param> public static IDomainResult <TValue> Failed(IEnumerable <ValidationResult> validationResults) => new DomainResult <TValue>(DomainResult.Failed(validationResults));
/// <summary> /// Get 'error' status. Gets be converted to HTTP code 400/422 /// </summary> /// <param name="errors"> Custom messages </param> public static IDomainResult <TValue> Failed(IEnumerable <string> errors) => new DomainResult <TValue>(DomainResult.Failed(errors));
/// <summary> /// Get 'not found' status. Gets converted to HTTP code 404 (NotFound) /// </summary> /// <typeparam name="TValue"> The expected value type if the operation was successful </typeparam> /// <param name="messages"> Custom messages </param> public static IDomainResult <TValue> NotFound <TValue>(IEnumerable <string> messages) => DomainResult <TValue> .NotFound(messages);
/// <summary> /// Convert to a <see cref="Task" /> of <see cref="IDomainResult{T}" /> (the domain operation result with a returned /// value) /// </summary> /// <typeparam name="T"> Value type of returned by the domain operation </typeparam> public static async Task <IDomainResult <T> > To <T>(this Task <IDomainResult> domainResult) { return(DomainResult <T> .From(await domainResult)); }
/// <summary> /// Get 'Unauthorized' status. Gets converted to HTTP code 403 (Forbidden) /// </summary> /// <typeparam name="TValue"> The expected value type if the operation was successful </typeparam> /// <param name="message"> Optional message </param> public static IDomainResult <TValue> Unauthorized <TValue>(string?message = null) => DomainResult <TValue> .Unauthorized(message);
/// <summary> /// Convert to a <see cref="IDomainResult{T}" /> with a new value type <typeparamref name="TNew"/> /// </summary> /// <typeparam name="TOld"> The old value type (converting from) </typeparam> /// <typeparam name="TNew"> The new value type (converting to) </typeparam> public static IDomainResult <TNew> To <TOld, TNew>(this IDomainResult <TOld> domainResult) { return(DomainResult <TNew> .From(domainResult)); }
/// <summary> /// Get 'error' status. Gets converted to HTTP code 400/422 /// </summary> /// <typeparam name="TValue"> The expected value type if the operation was successful </typeparam> /// <param name="errors"> Custom messages </param> public static IDomainResult <TValue> Failed <TValue>(IEnumerable <string> errors) => DomainResult <TValue> .Failed(errors);
/// <summary> /// Convert to a <see cref="Task"/> of <see cref="IDomainResult{T}" /> with a new value type <typeparamref name="TNew"/> /// </summary> /// <typeparam name="TOld"> The old value type (converting from) </typeparam> /// <typeparam name="TNew"> The new value type (converting to) </typeparam> public static async Task <IDomainResult <TNew> > To <TOld, TNew>(this Task <IDomainResult <TOld> > domainResult) { return(DomainResult <TNew> .From(await domainResult)); }
/// <summary> /// Get 'success' status with a value (all wrapped in <see cref="Task{T}"/>). /// Gets converted to HTTP code 200 (Ok) /// </summary> /// <typeparam name="TValue"> The value type </typeparam> /// <param name="value"> The value to be returned </param> public static Task <IDomainResult <TValue> > SuccessTask <TValue>(TValue value) => DomainResult <TValue> .SuccessTask(value);
/// <summary> /// Get 'error' status wrapped in a <see cref="Task{T}"/>. Gets converted to HTTP code 400/422 /// </summary> /// <typeparam name="TValue"> The expected value type if the operation was successful </typeparam> /// <param name="errors"> Custom messages </param> public static Task <IDomainResult <TValue> > FailedTask <TValue>(IEnumerable <string> errors) => DomainResult <TValue> .FailedTask(errors);
/// <summary> /// Get 'not found' status wrapped in a <see cref="Task{T}"/>. Gets converted to HTTP code 404 (NotFound) /// </summary> /// <typeparam name="TValue"> The expected value type if the operation was successful </typeparam> /// <param name="messages"> Custom messages </param> public static Task <IDomainResult <TValue> > NotFoundTask <TValue>(IEnumerable <string> messages) => DomainResult <TValue> .NotFoundTask(messages);
/// <summary> /// Get 'error' status wrapped in a <see cref="Task{T}"/>. Gets converted to HTTP code 400/422 /// </summary> /// <typeparam name="TValue"> The expected value type if the operation was successful </typeparam> /// <param name="validationResults"> Results of a validation request </param> public static Task <IDomainResult <TValue> > FailedTask <TValue>(IEnumerable <ValidationResult> validationResults) => DomainResult <TValue> .FailedTask(validationResults);
/// <summary> /// Get 'error' status wrapped in a <see cref="Task{T}"/>. Gets converted to HTTP code 400/422 /// </summary> /// <typeparam name="TValue"> The expected value type if the operation was successful </typeparam> /// <param name="error"> Optional message </param> public static Task <IDomainResult <TValue> > FailedTask <TValue>(string?error = null) => DomainResult <TValue> .FailedTask(error);
/// <summary> /// Get 'Unauthorized' status. Gets converted to HTTP code 403 (Forbidden) /// </summary> /// <param name="message"> Optional message </param> public static IDomainResult <TValue> Unauthorized(string?message = null) => new DomainResult <TValue>(DomainResult.Unauthorized(message));