Commit 3c33530b authored by Ryan Nowak's avatar Ryan Nowak
Browse files

Associate each order with a user

parent c992ab9e
......@@ -24,6 +24,7 @@ namespace BlazingPizza.Server
public async Task<ActionResult<List<OrderWithStatus>>> GetOrders()
{
var orders = await _db.Orders
.Where(o => o.UserId == GetUserId())
.Include(o => o.Pizzas).ThenInclude(p => p.Special)
.Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping)
.OrderByDescending(o => o.CreatedTime)
......@@ -37,6 +38,7 @@ namespace BlazingPizza.Server
{
var order = await _db.Orders
.Where(o => o.OrderId == orderId)
.Where(o => o.UserId == GetUserId())
.Include(o => o.Pizzas).ThenInclude(p => p.Special)
.Include(o => o.Pizzas).ThenInclude(p => p.Toppings).ThenInclude(t => t.Topping)
.SingleOrDefaultAsync();
......@@ -54,10 +56,17 @@ namespace BlazingPizza.Server
{
order.CreatedTime = DateTime.Now;
order.DeliveryLocation = new LatLong(51.5001, -0.1239);
order.UserId = GetUserId();
_db.Orders.Attach(order);
await _db.SaveChangesAsync();
return NoContent();
}
private string GetUserId()
{
// This will be the user's twitter username
return HttpContext.User.FindFirst("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name")?.Value;
}
}
}
......@@ -7,6 +7,8 @@ namespace BlazingPizza
{
public int OrderId { get; set; }
public string UserId { get; set; }
public DateTime CreatedTime { get; set; }
public LatLong DeliveryLocation { get; set; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment