Fix 147 include order id in details query (#169)

* Adding Id to query so the correct order details are always pulled back

* Removing unused usings

- also removed the sync method as it is not used anywhere in the solution. The Async should be the preferred one.

* Adding integration test for GetByIdWithItemAsync

* Rename test
This commit is contained in:
Eric Fleming
2018-12-14 20:54:23 -05:00
committed by Steve Smith
parent c7c16c4265
commit 0d44a514ab
3 changed files with 66 additions and 13 deletions

View File

@@ -1,7 +1,6 @@
using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate;
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.eShopWeb.Infrastructure.Data
@@ -11,21 +10,13 @@ namespace Microsoft.eShopWeb.Infrastructure.Data
public OrderRepository(CatalogContext dbContext) : base(dbContext)
{
}
public Order GetByIdWithItems(int id)
{
return _dbContext.Orders
.Include(o => o.OrderItems)
.Include($"{nameof(Order.OrderItems)}.{nameof(OrderItem.ItemOrdered)}")
.FirstOrDefault();
}
public Task<Order> GetByIdWithItemsAsync(int id)
{
return _dbContext.Orders
.Include(o => o.OrderItems)
.Include($"{nameof(Order.OrderItems)}.{nameof(OrderItem.ItemOrdered)}")
.FirstOrDefaultAsync();
.FirstOrDefaultAsync(x => x.Id == id);
}
}
}