@@ -29,14 +29,17 @@ public IEnumerable<Contact> GetContact()
2929
3030 // GET: api/ContactsApi/5
3131 [ HttpGet ( "{id}" ) ]
32+ [ ProducesResponseType ( typeof ( Contact ) , 200 ) ]
33+ [ ProducesResponseType ( typeof ( IDictionary < string , string > ) , 400 ) ]
34+ [ ProducesResponseType ( typeof ( void ) , 404 ) ]
3235 public async Task < IActionResult > GetContact ( [ FromRoute ] int id )
3336 {
3437 if ( ! ModelState . IsValid )
3538 {
3639 return BadRequest ( ModelState ) ;
3740 }
3841
39- Contact contact = await _context . Contact . SingleOrDefaultAsync ( m => m . Id == id ) ;
42+ var contact = await _context . Contact . SingleOrDefaultAsync ( m => m . Id == id ) ;
4043
4144 if ( contact == null )
4245 {
@@ -48,6 +51,11 @@ public async Task<IActionResult> GetContact([FromRoute] int id)
4851
4952 // PUT: api/ContactsApi/5
5053 [ HttpPut ( "{id}" ) ]
54+ [ ProducesResponseType ( typeof ( Contact ) , 200 ) ]
55+ [ ProducesResponseType ( typeof ( IDictionary < string , string > ) , 400 ) ]
56+ [ ProducesResponseType ( typeof ( void ) , 400 ) ]
57+ [ ProducesResponseType ( typeof ( void ) , 404 ) ]
58+ [ ProducesResponseType ( typeof ( void ) , 204 ) ]
5159 public async Task < IActionResult > PutContact ( [ FromRoute ] int id , [ FromBody ] Contact contact )
5260 {
5361 if ( ! ModelState . IsValid )
@@ -72,17 +80,20 @@ public async Task<IActionResult> PutContact([FromRoute] int id, [FromBody] Conta
7280 {
7381 return NotFound ( ) ;
7482 }
75- else
76- {
77- throw ;
78- }
83+
84+ throw ;
7985 }
8086
8187 return NoContent ( ) ;
8288 }
8389
8490 // POST: api/ContactsApi
8591 [ HttpPost ]
92+ [ ProducesResponseType ( typeof ( Contact ) , 200 ) ]
93+ [ ProducesResponseType ( typeof ( IDictionary < string , string > ) , 400 ) ]
94+ [ ProducesResponseType ( typeof ( void ) , 400 ) ]
95+ [ ProducesResponseType ( typeof ( void ) , 404 ) ]
96+ [ ProducesResponseType ( typeof ( void ) , 409 ) ]
8697 public async Task < IActionResult > PostContact ( [ FromBody ] Contact contact )
8798 {
8899 if ( ! ModelState . IsValid )
@@ -101,25 +112,26 @@ public async Task<IActionResult> PostContact([FromBody] Contact contact)
101112 {
102113 return new StatusCodeResult ( StatusCodes . Status409Conflict ) ;
103114 }
104- else
105- {
106- throw ;
107- }
115+ throw ;
108116 }
109117
110118 return CreatedAtAction ( "GetContact" , new { id = contact . Id } , contact ) ;
111119 }
112120
113121 // DELETE: api/ContactsApi/5
114122 [ HttpDelete ( "{id}" ) ]
123+ [ ProducesResponseType ( typeof ( Contact ) , 200 ) ]
124+ [ ProducesResponseType ( typeof ( IDictionary < string , string > ) , 400 ) ]
125+ [ ProducesResponseType ( typeof ( void ) , 400 ) ]
126+ [ ProducesResponseType ( typeof ( void ) , 404 ) ]
115127 public async Task < IActionResult > DeleteContact ( [ FromRoute ] int id )
116128 {
117129 if ( ! ModelState . IsValid )
118130 {
119131 return BadRequest ( ModelState ) ;
120132 }
121133
122- Contact contact = await _context . Contact . SingleOrDefaultAsync ( m => m . Id == id ) ;
134+ var contact = await _context . Contact . SingleOrDefaultAsync ( m => m . Id == id ) ;
123135 if ( contact == null )
124136 {
125137 return NotFound ( ) ;
0 commit comments