Пример #1
0
    /// <inheritdoc/>
    public Task ExecuteAsync(HttpContext httpContext)
    {
        ArgumentNullException.ThrowIfNull(httpContext);

        // Creating the logger with a string to preserve the category after the refactoring.
        var loggerFactory = httpContext.RequestServices.GetRequiredService <ILoggerFactory>();
        var logger        = loggerFactory.CreateLogger("Microsoft.AspNetCore.Http.Result.BadRequestObjectResult");

        HttpResultsHelper.Log.WritingResultAsStatusCode(logger, StatusCode);
        httpContext.Response.StatusCode = StatusCode;

        return(HttpResultsHelper.WriteResultAsJsonAsync(
                   httpContext,
                   logger: logger,
                   Value));
    }
Пример #2
0
    /// <inheritdoc/>
    public Task ExecuteAsync(HttpContext httpContext)
    {
        ArgumentNullException.ThrowIfNull(httpContext);

        var loggerFactory = httpContext.RequestServices.GetRequiredService <ILoggerFactory>();
        var logger        = loggerFactory.CreateLogger(typeof(ProblemHttpResult));

        if (StatusCode is { } code)
        {
            HttpResultsHelper.Log.WritingResultAsStatusCode(logger, code);
            httpContext.Response.StatusCode = code;
        }

        return(HttpResultsHelper.WriteResultAsJsonAsync <object?>(
                   httpContext,
                   logger,
                   value: ProblemDetails,
                   ContentType));
    }
Пример #3
0
    /// <summary>
    /// Initializes a new instance of the <see cref="Accepted"/> class with the values
    /// provided.
    /// </summary>
    /// <param name="locationUri">The location at which the status of requested content can be monitored.</param>
    /// <param name="value">The value to format in the entity body.</param>
    internal Accepted(Uri locationUri, TValue?value)
    {
        Value = value;
        HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode);

        if (locationUri == null)
        {
            throw new ArgumentNullException(nameof(locationUri));
        }

        if (locationUri.IsAbsoluteUri)
        {
            Location = locationUri.AbsoluteUri;
        }
        else
        {
            Location = locationUri.GetComponents(UriComponents.SerializationInfoString, UriFormat.UriEscaped);
        }
    }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Ok"/> class with the values.
 /// </summary>
 /// <param name="value">The value to format in the entity body.</param>
 internal Ok(TValue?value)
 {
     Value = value;
     HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode);
 }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UnprocessableEntity"/> class with the values
 /// provided.
 /// </summary>
 /// <param name="value">The value to format in the entity body.</param>
 internal UnprocessableEntity(TValue?value)
 {
     Value = value;
     HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode);
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BadRequest"/> class with the values
 /// provided.
 /// </summary>
 /// <param name="error">The error content to format in the entity body.</param>
 internal BadRequest(TValue?error)
 {
     Value = error;
     HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode);
 }
Пример #7
0
 /// <summary>
 /// Creates a new <see cref="ProblemHttpResult"/> instance with
 /// the provided <paramref name="problemDetails"/>.
 /// </summary>
 /// <param name="problemDetails">The <see cref="ProblemDetails"/> instance to format in the entity body.</param>
 internal ProblemHttpResult(ProblemDetails problemDetails)
 {
     ProblemDetails = problemDetails;
     HttpResultsHelper.ApplyProblemDetailsDefaults(ProblemDetails, statusCode: null);
 }
Пример #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Accepted"/> class with the values
 /// provided.
 /// </summary>
 /// <param name="location">The location at which the status of requested content can be monitored.</param>
 /// <param name="value">The value to format in the entity body.</param>
 internal Accepted(string?location, TValue?value)
 {
     Value    = value;
     Location = location;
     HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode);
 }