Browse Source

CreateOrder refactored so return code lines are more compact

pull/181/head
Cesar De la Torre 7 years ago
parent
commit
b1c0c72ec7
2 changed files with 5 additions and 9 deletions
  1. +1
    -1
      eShopOnContainers-ServicesAndWebApps.sln
  2. +4
    -8
      src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs

+ 1
- 1
eShopOnContainers-ServicesAndWebApps.sln 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


+ 4
- 8
src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs 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}")]


Loading…
Cancel
Save