Last active
April 4, 2020 10:21
-
-
Save DavidRogersDev/d2ead2c8d461bdeb27031b0e6978bcc0 to your computer and use it in GitHub Desktop.
Gist for Medium Article - CreateUser
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
[HttpPost] | |
[Route("[action]")] | |
public async Task<IActionResult> CreateUser([FromBody]CreateUserDto userDto) | |
{ | |
var result = await _mediator.Send(new CreateNewUserCommand {CreateUserDto = userDto}); | |
return result.IsValidResponse | |
? CreatedAtRoute(routeValues: new | |
{ | |
controller = "User", | |
action = nameof(UserController.GetUser), | |
id = result.Result.Data | |
version = HttpContext.GetRequestedApiVersion().ToString() | |
}, result.Result) | |
: BadRequestResponse(Enumerable.Empty<string>(), operationOutcome: new OperationOutcome | |
{ | |
OpResult =OpResult.Fail, | |
IsError = false, | |
IsValidationFail = true, | |
Errors = result.Errors | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment