|
@@ -0,0 +1,65 @@
|
|
1
|
+using Microsoft.AspNetCore.Mvc;
|
|
2
|
+using ProRestaurant.Models.Restaurants;
|
|
3
|
+using ProRestaurant.Repository.Restaurants;
|
|
4
|
+using System.Linq;
|
|
5
|
+using System.Transactions;
|
|
6
|
+
|
|
7
|
+namespace ProRestaurant.Controllers.Restaurants
|
|
8
|
+{
|
|
9
|
+ [Route("api/[controller]")]
|
|
10
|
+ [ApiController]
|
|
11
|
+ public class MenuCategoryController : ControllerBase
|
|
12
|
+ {
|
|
13
|
+ private readonly IMenuCategoryRepository repo;
|
|
14
|
+
|
|
15
|
+ public MenuCategoryController(IMenuCategoryRepository _repo)
|
|
16
|
+ {
|
|
17
|
+ repo = _repo;
|
|
18
|
+ }
|
|
19
|
+
|
|
20
|
+ [HttpGet("{id}")]
|
|
21
|
+ public IActionResult Get(int id)
|
|
22
|
+ {
|
|
23
|
+ return new OkObjectResult(repo.GetMenuCategory(r => r.Id == id));
|
|
24
|
+ }
|
|
25
|
+
|
|
26
|
+ [HttpGet("GetRestaurantCategories/{id}")]
|
|
27
|
+ public IActionResult GetRestaurantCategories(int id)
|
|
28
|
+ {
|
|
29
|
+ return new OkObjectResult(repo.GetMenuCategories(r => r.RestaurantId == id).OrderBy(r => r.Description));
|
|
30
|
+ }
|
|
31
|
+
|
|
32
|
+ [HttpPost]
|
|
33
|
+ public IActionResult Post([FromBody] MenuCategory menuCategory)
|
|
34
|
+ {
|
|
35
|
+ using (var scope = new TransactionScope())
|
|
36
|
+ {
|
|
37
|
+ repo.Insert(menuCategory);
|
|
38
|
+ scope.Complete();
|
|
39
|
+ return CreatedAtAction(nameof(Get), new { id = menuCategory.Id }, menuCategory);
|
|
40
|
+ }
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ [HttpPut]
|
|
44
|
+ public IActionResult Put([FromBody] MenuCategory menuCategory)
|
|
45
|
+ {
|
|
46
|
+ if (menuCategory != null)
|
|
47
|
+ {
|
|
48
|
+ using (var scope = new TransactionScope())
|
|
49
|
+ {
|
|
50
|
+ repo.Update(menuCategory);
|
|
51
|
+ scope.Complete();
|
|
52
|
+ return new OkResult();
|
|
53
|
+ }
|
|
54
|
+ }
|
|
55
|
+ return new NoContentResult();
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ [HttpDelete("{id}")]
|
|
59
|
+ public IActionResult Delete(int id)
|
|
60
|
+ {
|
|
61
|
+ repo.Remove(repo.GetMenuCategory(u => u.Id == id));
|
|
62
|
+ return new OkResult();
|
|
63
|
+ }
|
|
64
|
+ }
|
|
65
|
+}
|