File tree Expand file tree Collapse file tree 4 files changed +27
-8
lines changed
NorthwindCRUD/Controllers Expand file tree Collapse file tree 4 files changed +27
-8
lines changed Original file line number Diff line number Diff 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 ) ) ;
Original file line number Diff line number Diff 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 ) ) ;
Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff 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 ) ) ;
You can’t perform that action at this time.
0 commit comments