CreateOrder refactored so return code lines are more compact

This commit is contained in:
Cesar De la Torre 2017-05-03 18:36:52 -07:00
parent 17b3e0f14d
commit b1c0c72ec7
2 changed files with 5 additions and 9 deletions

View File

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26403.7
VisualStudioVersion = 15.0.26403.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{932D8224-11F6-4D07-B109-DA28AD288A63}"
EndProject

View File

@ -30,25 +30,21 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
[HttpPost]
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)
{
var requestCreateOrder = new IdentifiedCommand<CreateOrderCommand, bool>(command, guid);
result = await _mediator.SendAsync(requestCreateOrder);
commandResult = await _mediator.SendAsync(requestCreateOrder);
}
else
{
// 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.
result = await _mediator.SendAsync(command);
commandResult = await _mediator.SendAsync(command);
}
if (result)
{
return Ok();
}
return commandResult ? (StatusCodeResult)Ok() : (StatusCodeResult)BadRequest();
return BadRequest();
}
[Route("{orderId:int}")]