Browse Source

add back the async state machine

Because of the using blocks, these one line methods need the async
modifier so that the that async state machiner is created. Otherwise, if
the method does not complete synchronously, the connection is closed
before the database has returned its results.
pull/181/head
BillWagner 7 years ago
committed by Bill Wagner
parent
commit
223dcda0cb
2 changed files with 7 additions and 6 deletions
  1. +4
    -4
      src/Services/Ordering/Ordering.API/Application/Queries/OrderQueries.cs
  2. +3
    -2
      src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs

+ 4
- 4
src/Services/Ordering/Ordering.API/Application/Queries/OrderQueries.cs View File

@ -44,13 +44,13 @@
}
}
public Task<IEnumerable<dynamic>> GetOrdersAsync()
public async Task<IEnumerable<dynamic>> GetOrdersAsync()
{
using (var connection = new SqlConnection(_connectionString))
{
connection.Open();
return connection.QueryAsync<dynamic>(@"SELECT o.[Id] as ordernumber,o.[OrderDate] as [date],os.[Name] as [status],SUM(oi.units*oi.unitprice) as total
return await connection.QueryAsync<dynamic>(@"SELECT o.[Id] as ordernumber,o.[OrderDate] as [date],os.[Name] as [status],SUM(oi.units*oi.unitprice) as total
FROM [ordering].[Orders] o
LEFT JOIN[ordering].[orderitems] oi ON o.Id = oi.orderid
LEFT JOIN[ordering].[orderstatus] os on o.OrderStatusId = os.Id
@ -58,13 +58,13 @@
}
}
public Task<IEnumerable<dynamic>> GetCardTypesAsync()
public async Task<IEnumerable<dynamic>> GetCardTypesAsync()
{
using (var connection = new SqlConnection(_connectionString))
{
connection.Open();
return connection.QueryAsync<dynamic>("SELECT * FROM ordering.cardtypes");
return await connection.QueryAsync<dynamic>("SELECT * FROM ordering.cardtypes");
}
}


+ 3
- 2
src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs View File

@ -68,8 +68,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
[HttpGet]
public async Task<IActionResult> GetOrders()
{
var orders = await _orderQueries
.GetOrdersAsync();
var orderTask = _orderQueries.GetOrdersAsync();
var orders = await orderTask;
return Ok(orders);
}


Loading…
Cancel
Save