Skip to content

Commit b1c0c72

Browse files
CreateOrder refactored so return code lines are more compact
1 parent 17b3e0f commit b1c0c72

2 files changed

Lines changed: 5 additions & 9 deletions

File tree

eShopOnContainers-ServicesAndWebApps.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

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

src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,21 @@ public OrdersController(IMediator mediator, IOrderQueries orderQueries, IIdentit
3030
[HttpPost]
3131
public async Task<IActionResult> CreateOrder([FromBody]CreateOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId)
3232
{
33-
bool result = false;
33+
bool commandResult = false;
3434
if (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty)
3535
{
3636
var requestCreateOrder = new IdentifiedCommand<CreateOrderCommand, bool>(command, guid);
37-
result = await _mediator.SendAsync(requestCreateOrder);
37+
commandResult = await _mediator.SendAsync(requestCreateOrder);
3838
}
3939
else
4040
{
4141
// If no x-requestid header is found we process the order anyway. This is just temporary to not break existing clients
4242
// that aren't still updated. When all clients were updated this could be removed.
43-
result = await _mediator.SendAsync(command);
43+
commandResult = await _mediator.SendAsync(command);
4444
}
4545

46-
if (result)
47-
{
48-
return Ok();
49-
}
46+
return commandResult ? (StatusCodeResult)Ok() : (StatusCodeResult)BadRequest();
5047

51-
return BadRequest();
5248
}
5349

5450
[Route("{orderId:int}")]

0 commit comments

Comments
 (0)