コード例 #1
0
        private async Task MultipleErrorsWithValueHandler(HttpRequest request, HttpResponse response, RouteData data)
        {
            var executor = new MultipleErrorsWithValue.Executor();
            var result   = executor.Operation();

            if (result.Succeeded)
            {
                await response.WriteAsync($"Operation succeeded with a value of '{result.Value}'.");
            }
            else
            {
                var json = JsonSerializer.Serialize(result.Errors);
                response.Headers["ContentType"] = "application/json";

                await response.WriteAsync(json);
            }
        }
コード例 #2
0
        private async Task MultipleErrorsWithValueHandler(HttpRequest request, HttpResponse response, RouteData data)
        {
            // Create an instance of the class that contains the operation
            var executor = new MultipleErrorsWithValue.Executor();

            // Execute the operation and handle its result
            var result = executor.Operation();

            if (result.Succeeded)
            {
                // Handle the success
                await response.WriteAsync($"Operation succeeded with a value of '{result.Value}'.");
            }
            else
            {
                // Handle the failure
                var json = JsonSerializer.Serialize(result.Errors);
                response.Headers["ContentType"] = "application/json";
                await response.WriteAsync(json);
            }
        }