Skip to content

Commit 46a77d6

Browse files
committed
fix employees endpoints
1 parent cb3d526 commit 46a77d6

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

NorthwindCRUD/Controllers/EmployeesController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public ActionResult<EmployeeDto> GetById(int id)
6060
}
6161
}
6262

63+
// TODO Add additional data in order to support this endpoint
6364
[HttpGet("{id}/Superior")]
6465
[Authorize]
6566
public ActionResult<EmployeeDto> GetSuperiorById(int id)
@@ -111,7 +112,7 @@ public ActionResult<OrderDto[]> GetOrdersByEmployeeId(int id)
111112
var employee = this.employeeService.GetById(id);
112113
if (employee != null)
113114
{
114-
return Ok(this.mapper.Map<OrderDb[], OrderDto>(employee.Orders.ToArray()));
115+
return Ok(this.mapper.Map<OrderDb[], OrderDto[]>(employee.Orders.ToArray()));
115116
}
116117

117118
return NotFound();

NorthwindCRUD/Services/CustomerService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public CustomerDb GetById(string id)
2525
{
2626
return this.dataContext.Customers
2727
.Include(c => c.Address)
28-
.Include(c => c.Orders.Where(o => o.CustomerId == id))
28+
.Include(c => c.Orders.Where(o => o.CustomerId == id))
2929
.FirstOrDefault(c => c.CustomerId == id);
3030
}
3131

NorthwindCRUD/Services/EmployeeService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public EmployeeDb GetById(int id)
2424
{
2525
return this.dataContext.Employees
2626
.Include(c => c.Address)
27+
.Include(c => c.Orders.Where(o => o.EmployeeId == id))
28+
.Include(c => c.EmployeesTerritories.Where(o => o.EmployeeId == id))
29+
.ThenInclude(t => t.Territory)
2730
.FirstOrDefault(c => c.EmployeeId == id);
2831
}
2932

0 commit comments

Comments
 (0)