-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Demonstrate non-gen Controller operation.
- Loading branch information
Showing
12 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
samples/Demo/Beef.Demo.Api/Controllers/PersonController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#nullable enable | ||
|
||
using CoreEx.Results; | ||
|
||
namespace Beef.Demo.Api.Controllers | ||
{ | ||
public partial class PersonController | ||
{ | ||
/// <summary> | ||
/// Extend Response. | ||
/// </summary> | ||
/// <returns>A resultant <c>string</c>.</returns> | ||
[HttpPost("api/v1/persons/extend-response", Name = "Person_ExtendResponse")] | ||
[ProducesResponseType(typeof(string), (int)HttpStatusCode.OK)] | ||
[ProducesResponseType((int)HttpStatusCode.NoContent)] | ||
public Task<IActionResult> ExtendResponse(string? name) | ||
=> _webApi.PostWithResultAsync(Request, p => | ||
{ | ||
return Result.GoAsync(() => _manager.ExtendResponseAsync(name)) // Execute the business logic. | ||
.ThenAs(r => // Then handle response where Result.IsSuccess; otherwise, allow to bubble out. | ||
{ | ||
var ia = ValueContentResult.CreateResult(r, HttpStatusCode.OK, null, _webApi.JsonSerializer, p.RequestOptions, false, null); // Use standard CoreEx ValueContentResult to handle the response. | ||
if (ia is ValueContentResult vcr) // Ensure is a ValueContentResult, and if so, then manipulate. | ||
{ | ||
vcr.BeforeExtension = hr => // Extend the reponse by adding a new header. | ||
{ | ||
hr.Headers.Add("X-Beef-Test", "123"); | ||
return Task.CompletedTask; | ||
}; | ||
} | ||
return ia; | ||
}); | ||
}, alternateStatusCode: HttpStatusCode.NoContent, operationType: CoreEx.OperationType.Unspecified); | ||
} | ||
} | ||
|
||
#nullable restore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters