1
- using AutoMapper ;
2
- using Microsoft . AspNetCore . Mvc ;
3
- using Microsoft . EntityFrameworkCore ;
4
- using WebAPI . Entities ;
1
+ using Microsoft . AspNetCore . Mvc ;
5
2
using WebAPI . Models ;
6
3
using WebAPI . Serivces ;
7
4
8
5
namespace WebAPI . Controllers
9
6
{
10
7
[ Route ( "api/restaurant" ) ]
8
+ [ ApiController ]
11
9
public class RestaurantController : ControllerBase
12
10
{
13
-
11
+
14
12
private readonly IRestauranServices _restaurantService ;
15
13
16
14
public RestaurantController ( IRestauranServices restauranServices )
@@ -21,45 +19,35 @@ public RestaurantController(IRestauranServices restauranServices)
21
19
public ActionResult < IEnumerable < RestaurantDto > > GetAll ( )
22
20
{
23
21
var resutarants = _restaurantService . GetAll ( ) ;
24
- return resutarants . Any ( ) ? Ok ( resutarants ) : BadRequest ( ) ;
22
+ return resutarants . Any ( ) ? Ok ( resutarants ) : BadRequest ( ) ;
25
23
}
26
24
27
25
[ HttpGet ( "{id}" ) ]
28
26
public ActionResult < RestaurantDto > Get ( [ FromRoute ] int id )
29
27
{
30
- var restaurant = _restaurantService . GetById ( id ) ;
31
- return restaurant == null ? NotFound ( ) : Ok ( restaurant ) ;
28
+ var restaurant = _restaurantService . GetById ( id ) ;
29
+ return Ok ( restaurant ) ;
32
30
}
33
31
34
32
[ HttpPost ]
35
33
public ActionResult CreateRestaurant ( [ FromBody ] CreateRestuarantDto dto )
36
34
{
37
- if ( ! ModelState . IsValid )
38
- {
39
- return BadRequest ( ModelState ) ;
40
- }
41
-
42
35
int id = _restaurantService . Create ( dto ) ;
43
36
return Created ( $ "/api/restuarant/{ id } ", "ok pomyslnie dodoano" ) ;
44
37
}
45
38
[ HttpDelete ( "{id}" ) ]
46
39
public ActionResult Delete ( [ FromRoute ] int id )
47
40
{
48
- bool flag = _restaurantService . Delete ( id ) ;
49
-
50
- return flag ? NoContent ( ) : NotFound ( ) ;
41
+ _restaurantService . Delete ( id ) ;
42
+ return NoContent ( ) ;
51
43
52
44
}
53
45
[ HttpPut ]
54
46
public ActionResult < RestaurantDto > UpdateRestaurant ( [ FromBody ] UpdateRestaurantDto dto )
55
47
{
56
- if ( ! ModelState . IsValid )
57
- {
58
- return BadRequest ( ModelState ) ;
59
- }
60
- bool flag = _restaurantService . UpdateRestaurant ( dto ) ;
48
+ _restaurantService . UpdateRestaurant ( dto ) ;
61
49
var updatedRestaruant = _restaurantService . GetById ( dto . Id ) ;
62
- return flag ? Ok ( updatedRestaruant ) : BadRequest ( ) ;
50
+ return Ok ( updatedRestaruant ) ;
63
51
}
64
52
}
65
53
}
0 commit comments