@ -7,7 +7,7 @@
using System.Collections.Generic ;
using System.Collections.Generic ;
public class OrderQueries
public class OrderQueries
: IOrderQueries
: IOrderQueries
{
{
private string _connectionString = string . Empty ;
private string _connectionString = string . Empty ;
@ -42,18 +42,20 @@
}
}
}
}
public async Task < IEnumerable < OrderSummary > > GetOrdersAsync ( )
public async Task < IEnumerable < OrderSummary > > GetOrdersFromUser Async ( Guid userId )
{
{
using ( var connection = new SqlConnection ( _connectionString ) )
using ( var connection = new SqlConnection ( _connectionString ) )
{
{
connection . Open ( ) ;
connection . Open ( ) ;
return await connection . QueryAsync < OrderSummary > ( @ "SELECT o.[Id] as ordernumber,o.[OrderDate] as [date],os.[Name] as [status],SUM(oi.units*oi.unitprice) as total
return await connection . QueryAsync < OrderSummary > ( @ "SELECT o.[Id] as ordernumber,o.[OrderDate] as [date],os.[Name] as [status], SUM(oi.units*oi.unitprice) as total
FROM [ ordering ] . [ Orders ] o
FROM [ ordering ] . [ Orders ] o
LEFT JOIN [ ordering ] . [ orderitems ] oi ON o . Id = oi . orderid
LEFT JOIN [ ordering ] . [ orderitems ] oi ON o . Id = oi . orderid
LEFT JOIN [ ordering ] . [ orderstatus ] os on o . OrderStatusId = os . Id
LEFT JOIN [ ordering ] . [ orderstatus ] os on o . OrderStatusId = os . Id
LEFT JOIN [ ordering ] . [ buyers ] ob on o . BuyerId = ob . Id
WHERE ob . IdentityGuid = @userId
GROUP BY o . [ Id ] , o . [ OrderDate ] , os . [ Name ]
GROUP BY o . [ Id ] , o . [ OrderDate ] , os . [ Name ]
ORDER BY o . [ Id ] ");
ORDER BY o . [ Id ] ", new { userId } );
}
}
}
}