CreateOrder refactored so return code lines are more compact
This commit is contained in:
parent
17b3e0f14d
commit
b1c0c72ec7
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 15
|
# Visual Studio 15
|
||||||
VisualStudioVersion = 15.0.26403.7
|
VisualStudioVersion = 15.0.26403.3
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{932D8224-11F6-4D07-B109-DA28AD288A63}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{932D8224-11F6-4D07-B109-DA28AD288A63}"
|
||||||
EndProject
|
EndProject
|
||||||
|
@ -30,25 +30,21 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> CreateOrder([FromBody]CreateOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId)
|
public async Task<IActionResult> CreateOrder([FromBody]CreateOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool commandResult = false;
|
||||||
if (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty)
|
if (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty)
|
||||||
{
|
{
|
||||||
var requestCreateOrder = new IdentifiedCommand<CreateOrderCommand, bool>(command, guid);
|
var requestCreateOrder = new IdentifiedCommand<CreateOrderCommand, bool>(command, guid);
|
||||||
result = await _mediator.SendAsync(requestCreateOrder);
|
commandResult = await _mediator.SendAsync(requestCreateOrder);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// If no x-requestid header is found we process the order anyway. This is just temporary to not break existing clients
|
// If no x-requestid header is found we process the order anyway. This is just temporary to not break existing clients
|
||||||
// that aren't still updated. When all clients were updated this could be removed.
|
// that aren't still updated. When all clients were updated this could be removed.
|
||||||
result = await _mediator.SendAsync(command);
|
commandResult = await _mediator.SendAsync(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result)
|
return commandResult ? (StatusCodeResult)Ok() : (StatusCodeResult)BadRequest();
|
||||||
{
|
|
||||||
return Ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
return BadRequest();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("{orderId:int}")]
|
[Route("{orderId:int}")]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user