Skip to content

Commit 8711241

Browse files
authored
Merge pull request #9 from IgniteUI/snovoselski/update-category-put-endpoint
fix(put-endpoints): return NotFound with invalid id
2 parents 0341b81 + 238664b commit 8711241

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

NorthwindCRUD/Controllers/CategoryController.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public ActionResult<CategoryInputModel> GetById(int id)
4646
try
4747
{
4848
var category = this.categoryService.GetById(id);
49-
5049
if (category != null)
5150
{
5251
return Ok(this.mapper.Map<CategoryDb, CategoryInputModel>(category));
@@ -93,7 +92,13 @@ public ActionResult<CategoryInputModel> Update(CategoryInputModel model)
9392
{
9493
var mappedModel = this.mapper.Map<CategoryInputModel, CategoryDb>(model);
9594
var category = this.categoryService.Update(mappedModel);
96-
return Ok(this.mapper.Map<CategoryDb, CategoryInputModel>(category));
95+
96+
if (category != null)
97+
{
98+
return Ok(this.mapper.Map<CategoryDb, CategoryInputModel>(category));
99+
}
100+
101+
return NotFound();
97102
}
98103

99104
return BadRequest(ModelState);
@@ -112,7 +117,6 @@ public ActionResult<CategoryInputModel> Delete(int id)
112117
try
113118
{
114119
var category = this.categoryService.Delete(id);
115-
116120
if (category != null)
117121
{
118122
return Ok(this.mapper.Map<CategoryDb, CategoryInputModel>(category));

NorthwindCRUD/Controllers/CustomerController.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,13 @@ public ActionResult<CustomerInputModel> Update(CustomerInputModel model)
9292
{
9393
var mappedModel = this.mapper.Map<CustomerInputModel, CustomerDb>(model);
9494
var customer = this.customerService.Update(mappedModel);
95-
return Ok(this.mapper.Map<CustomerDb, CustomerInputModel>(customer));
95+
96+
if (customer != null)
97+
{
98+
return Ok(this.mapper.Map<CustomerDb, CustomerInputModel>(customer));
99+
}
100+
101+
return NotFound();
96102
}
97103

98104
return BadRequest(ModelState);
@@ -111,7 +117,6 @@ public ActionResult<CustomerInputModel> Delete(string id)
111117
try
112118
{
113119
var customer = this.customerService.Delete(id);
114-
115120
if (customer != null)
116121
{
117122
return Ok(this.mapper.Map<CustomerDb, CustomerInputModel>(customer));

NorthwindCRUD/Controllers/EmployeeController.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,13 @@ public ActionResult<EmployeeInputModel> Update(EmployeeInputModel model)
9292
{
9393
var mappedModel = this.mapper.Map<EmployeeInputModel, EmployeeDb>(model);
9494
var employee = this.employeeService.Update(mappedModel);
95-
return Ok(this.mapper.Map<EmployeeDb, EmployeeInputModel>(employee));
95+
96+
if (employee != null)
97+
{
98+
return Ok(this.mapper.Map<EmployeeDb, EmployeeInputModel>(employee));
99+
}
100+
101+
return NotFound();
96102
}
97103

98104
return BadRequest(ModelState);

NorthwindCRUD/Controllers/OrderController.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ public ActionResult<OrderInputModel> Update(OrderInputModel model)
9292
{
9393
var mappedModel = this.mapper.Map<OrderInputModel, OrderDb>(model);
9494
var order = this.orderService.Update(mappedModel);
95-
return Ok(this.mapper.Map<OrderDb, OrderInputModel>(order));
95+
if (order != null)
96+
{
97+
return Ok(this.mapper.Map<OrderDb, OrderInputModel>(order));
98+
}
99+
100+
return NotFound();
96101
}
97102

98103
return BadRequest(ModelState);
@@ -111,7 +116,6 @@ public ActionResult<OrderInputModel> Delete(int id)
111116
try
112117
{
113118
var order = this.orderService.Delete(id);
114-
115119
if (order != null)
116120
{
117121
return Ok(this.mapper.Map<OrderDb, OrderInputModel>(order));

0 commit comments

Comments
 (0)