File tree Expand file tree Collapse file tree 4 files changed +47
-8
lines changed
NorthwindCRUD/Controllers Expand file tree Collapse file tree 4 files changed +47
-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,12 @@ public ActionResult<CategoryInputModel> Delete(int id)
112117 try
113118 {
114119 var category = this . categoryService . Delete ( id ) ;
115- return Ok ( this . mapper . Map < CategoryDb , CategoryInputModel > ( category ) ) ;
120+ if ( category != null )
121+ {
122+ return Ok ( this . mapper . Map < CategoryDb , CategoryInputModel > ( category ) ) ;
123+ }
124+
125+ return NotFound ( ) ;
116126 }
117127 catch ( Exception error )
118128 {
Original file line number Diff line number Diff line change 33 using AutoMapper ;
44 using Microsoft . AspNetCore . Authorization ;
55 using Microsoft . AspNetCore . Mvc ;
6+ using NorthwindCRUD . Models . Contracts ;
67 using NorthwindCRUD . Models . DbModels ;
78 using NorthwindCRUD . Models . InputModels ;
89 using NorthwindCRUD . Services ;
@@ -92,7 +93,13 @@ public ActionResult<CustomerInputModel> Update(CustomerInputModel model)
9293 {
9394 var mappedModel = this . mapper . Map < CustomerInputModel , CustomerDb > ( model ) ;
9495 var customer = this . customerService . Update ( mappedModel ) ;
95- return Ok ( this . mapper . Map < CustomerDb , CustomerInputModel > ( customer ) ) ;
96+
97+ if ( customer != null )
98+ {
99+ return Ok ( this . mapper . Map < CustomerDb , CustomerInputModel > ( customer ) ) ;
100+ }
101+
102+ return NotFound ( ) ;
96103 }
97104
98105 return BadRequest ( ModelState ) ;
@@ -111,7 +118,12 @@ public ActionResult<CustomerInputModel> Delete(string id)
111118 try
112119 {
113120 var customer = this . customerService . Delete ( id ) ;
114- return Ok ( this . mapper . Map < CustomerDb , CustomerInputModel > ( customer ) ) ;
121+ if ( customer != null )
122+ {
123+ return Ok ( this . mapper . Map < CustomerDb , CustomerInputModel > ( customer ) ) ;
124+ }
125+
126+ return NotFound ( ) ;
115127 }
116128 catch ( Exception error )
117129 {
Original file line number Diff line number Diff line change 33 using AutoMapper ;
44 using Microsoft . AspNetCore . Authorization ;
55 using Microsoft . AspNetCore . Mvc ;
6+ using NorthwindCRUD . Models . Contracts ;
67 using NorthwindCRUD . Models . DbModels ;
78 using NorthwindCRUD . Models . InputModels ;
89 using NorthwindCRUD . Services ;
@@ -111,7 +112,13 @@ public ActionResult<EmployeeInputModel> Delete(int id)
111112 try
112113 {
113114 var employee = this . employeeService . Delete ( id ) ;
114- return Ok ( this . mapper . Map < EmployeeDb , EmployeeInputModel > ( employee ) ) ;
115+
116+ if ( employee != null )
117+ {
118+ return Ok ( this . mapper . Map < EmployeeDb , EmployeeInputModel > ( employee ) ) ;
119+ }
120+
121+ return NotFound ( ) ;
115122 }
116123 catch ( Exception error )
117124 {
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,12 @@ public ActionResult<OrderInputModel> Delete(int id)
111116 try
112117 {
113118 var order = this . orderService . Delete ( id ) ;
114- return Ok ( this . mapper . Map < OrderDb , OrderInputModel > ( order ) ) ;
119+ if ( order != null )
120+ {
121+ return Ok ( this . mapper . Map < OrderDb , OrderInputModel > ( order ) ) ;
122+ }
123+
124+ return NotFound ( ) ;
115125 }
116126 catch ( Exception error )
117127 {
You can’t perform that action at this time.
0 commit comments