瀏覽代碼

Restaurant Menu Category

master
George Williams 4 年之前
父節點
當前提交
de8cd3fa40

二進制
.vs/ProRestaurant/v16/.suo 查看文件


+ 65
- 0
ProRestaurant/Controllers/Restaurants/MenuCategoryController.cs 查看文件

@@ -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
+}

+ 1
- 0
ProRestaurant/Startup.cs 查看文件

@@ -77,6 +77,7 @@ namespace ProRestaurant
77 77
             services.AddTransient<IRestaurantCategoryRepository, RestaurantCategoryRepository>();
78 78
             services.AddTransient<IRestaurantRepository, RestaurantRepository>();
79 79
             services.AddTransient<IUserRepository, UserRepository>();
80
+            services.AddTransient<IMenuCategoryRepository, MenuCategoryRepository>();
80 81
 
81 82
             services.Configure<MvcOptions>(options =>
82 83
             {

二進制
ProRestaurant/bin/Debug/netcoreapp2.2/ProRestaurant.dll 查看文件


二進制
ProRestaurant/bin/Debug/netcoreapp2.2/ProRestaurant.pdb 查看文件


+ 1
- 1
ProRestaurant/obj/Debug/netcoreapp2.2/ProRestaurant.csproj.CoreCompileInputs.cache 查看文件

@@ -1 +1 @@
1
-95f31759ff509a3473cf7dbab60f1f45eea8a8ac
1
+7ee9c31cc58d25ebc38120ba0960c1c57a6e9ec2

二進制
ProRestaurant/obj/Debug/netcoreapp2.2/ProRestaurant.csprojAssemblyReference.cache 查看文件


二進制
ProRestaurant/obj/Debug/netcoreapp2.2/ProRestaurant.dll 查看文件


二進制
ProRestaurant/obj/Debug/netcoreapp2.2/ProRestaurant.pdb 查看文件


Loading…
取消
儲存