Browse Source

crud controller

tags/v0.1.0
Robin Thoni 8 years ago
parent
commit
484599434b

+ 28
- 28
Luticate2.Utils/Business/LuCrudBusiness.cs View File

@@ -6,17 +6,17 @@ using Luticate2.Utils.Interfaces;
6 6
 
7 7
 namespace Luticate2.Utils.Business
8 8
 {
9
-    public abstract class LuCrudBusiness<TNextCrud, TDboCreate, TDboRead, TDboUpdate> : LuBusiness, ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate>
10
-        where TNextCrud : ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate>
9
+    public abstract class LuCrudBusiness<TDataAccess, TDboCreate, TDboRead, TDboUpdate> : LuBusiness, ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate>
10
+        where TDataAccess : ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate>
11 11
         where TDboCreate : class
12 12
         where TDboRead : class
13 13
         where TDboUpdate : class
14 14
     {
15
-        protected readonly TNextCrud NextCrud;
15
+        protected readonly TDataAccess DataAccess;
16 16
 
17
-        protected LuCrudBusiness(TNextCrud nextCrud)
17
+        protected LuCrudBusiness(TDataAccess dataAccess)
18 18
         {
19
-            NextCrud = nextCrud;
19
+            DataAccess = dataAccess;
20 20
         }
21 21
 
22 22
         protected virtual LuResult<TDboCreate> CheckAdd(TDboCreate obj)
@@ -73,7 +73,7 @@ namespace Luticate2.Utils.Business
73 73
             {
74 74
                 return res.To<T>();
75 75
             }
76
-            return NextCrud.Add(res.Data, returnFunc);
76
+            return DataAccess.Add(res.Data, returnFunc);
77 77
         }
78 78
 
79 79
         public LuResult<T> Add<T>(TDboCreate obj, Func<TDboRead, T> returnFunc)
@@ -83,7 +83,7 @@ namespace Luticate2.Utils.Business
83 83
             {
84 84
                 return res.To<T>();
85 85
             }
86
-            return NextCrud.Add(res.Data, returnFunc);
86
+            return DataAccess.Add(res.Data, returnFunc);
87 87
         }
88 88
 
89 89
         public LuResult<IEnumerable<string>> AddGuid(IEnumerable<TDboCreate> objs)
@@ -93,7 +93,7 @@ namespace Luticate2.Utils.Business
93 93
             {
94 94
                 return res.To<IEnumerable<string>>();
95 95
             }
96
-            return NextCrud.AddGuid(res.Data);
96
+            return DataAccess.AddGuid(res.Data);
97 97
         }
98 98
 
99 99
         public LuResult<string> AddGuid(TDboCreate obj)
@@ -103,7 +103,7 @@ namespace Luticate2.Utils.Business
103 103
             {
104 104
                 return res.To<string>();
105 105
             }
106
-            return NextCrud.AddGuid(res.Data);
106
+            return DataAccess.AddGuid(res.Data);
107 107
         }
108 108
 
109 109
         public LuResult<IEnumerable<long>> AddId(IEnumerable<TDboCreate> obj)
@@ -113,7 +113,7 @@ namespace Luticate2.Utils.Business
113 113
             {
114 114
                 return res.To<IEnumerable<long>>();
115 115
             }
116
-            return NextCrud.AddId(res.Data);
116
+            return DataAccess.AddId(res.Data);
117 117
         }
118 118
 
119 119
         public LuResult<long> AddId(TDboCreate obj)
@@ -123,7 +123,7 @@ namespace Luticate2.Utils.Business
123 123
             {
124 124
                 return res.To<long>();
125 125
             }
126
-            return NextCrud.AddId(res.Data);
126
+            return DataAccess.AddId(res.Data);
127 127
         }
128 128
 
129 129
         public LuResult<IEnumerable<TDboRead>> AddDbo(IEnumerable<TDboCreate> obj)
@@ -133,7 +133,7 @@ namespace Luticate2.Utils.Business
133 133
             {
134 134
                 return res.To<IEnumerable<TDboRead>>();
135 135
             }
136
-            return NextCrud.AddDbo(res.Data);
136
+            return DataAccess.AddDbo(res.Data);
137 137
         }
138 138
 
139 139
         public LuResult<TDboRead> AddDbo(TDboCreate obj)
@@ -143,7 +143,7 @@ namespace Luticate2.Utils.Business
143 143
             {
144 144
                 return res.To<TDboRead>();
145 145
             }
146
-            return NextCrud.AddDbo(res.Data);
146
+            return DataAccess.AddDbo(res.Data);
147 147
         }
148 148
 
149 149
 
@@ -151,17 +151,17 @@ namespace Luticate2.Utils.Business
151 151
 
152 152
         public LuResult<TDboRead> GetSingleById(string id)
153 153
         {
154
-            return NextCrud.GetSingleById(id);
154
+            return DataAccess.GetSingleById(id);
155 155
         }
156 156
 
157 157
         public LuResult<TDboRead> GetSingleById(long id)
158 158
         {
159
-            return NextCrud.GetSingleById(id);
159
+            return DataAccess.GetSingleById(id);
160 160
         }
161 161
 
162 162
         public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, int page = 0, int perPage = int.MaxValue)
163 163
         {
164
-            return NextCrud.GetMultiple(orderBy, 0, perPage);
164
+            return DataAccess.GetMultiple(orderBy, 0, perPage);
165 165
         }
166 166
 
167 167
 
@@ -174,7 +174,7 @@ namespace Luticate2.Utils.Business
174 174
             {
175 175
                 return obj.To<T>();
176 176
             }
177
-            return NextCrud.EditSingleById(id, obj.Data, returnFunc);
177
+            return DataAccess.EditSingleById(id, obj.Data, returnFunc);
178 178
         }
179 179
 
180 180
         public LuResult<long> EditSingleByIdId(long id, TDboUpdate update)
@@ -184,7 +184,7 @@ namespace Luticate2.Utils.Business
184 184
             {
185 185
                 return obj.To<long>();
186 186
             }
187
-            return NextCrud.EditSingleByIdId(id, obj.Data);
187
+            return DataAccess.EditSingleByIdId(id, obj.Data);
188 188
         }
189 189
 
190 190
         public LuResult<TDboRead> EditSingleByIdDbo(long id, TDboUpdate update)
@@ -194,7 +194,7 @@ namespace Luticate2.Utils.Business
194 194
             {
195 195
                 return obj.To<TDboRead>();
196 196
             }
197
-            return NextCrud.EditSingleByIdDbo(id, obj.Data);
197
+            return DataAccess.EditSingleByIdDbo(id, obj.Data);
198 198
         }
199 199
 
200 200
         public LuResult<T> EditSingleById<T>(string id, TDboUpdate update, Func<TDboRead, T> returnFunc)
@@ -204,7 +204,7 @@ namespace Luticate2.Utils.Business
204 204
             {
205 205
                 return obj.To<T>();
206 206
             }
207
-            return NextCrud.EditSingleById(id, obj.Data, returnFunc);
207
+            return DataAccess.EditSingleById(id, obj.Data, returnFunc);
208 208
         }
209 209
 
210 210
         public LuResult<string> EditSingleByIdGuid(string id, TDboUpdate update)
@@ -214,7 +214,7 @@ namespace Luticate2.Utils.Business
214 214
             {
215 215
                 return obj.To<string>();
216 216
             }
217
-            return NextCrud.EditSingleByIdGuid(id, obj.Data);
217
+            return DataAccess.EditSingleByIdGuid(id, obj.Data);
218 218
         }
219 219
 
220 220
         public LuResult<TDboRead> EditSingleByIdDbo(string id, TDboUpdate update)
@@ -224,7 +224,7 @@ namespace Luticate2.Utils.Business
224 224
             {
225 225
                 return obj.To<TDboRead>();
226 226
             }
227
-            return NextCrud.EditSingleByIdDbo(id, obj.Data);
227
+            return DataAccess.EditSingleByIdDbo(id, obj.Data);
228 228
         }
229 229
 
230 230
 
@@ -232,32 +232,32 @@ namespace Luticate2.Utils.Business
232 232
 
233 233
         public LuResult<T> DeleteSingleById<T>(string id, Func<TDboRead, T> returnFunc)
234 234
         {
235
-            return NextCrud.DeleteSingleById(id, returnFunc);
235
+            return DataAccess.DeleteSingleById(id, returnFunc);
236 236
         }
237 237
 
238 238
         public LuResult<string> DeleteSingleByIdGuid(string id)
239 239
         {
240
-            return NextCrud.DeleteSingleByIdGuid(id);
240
+            return DataAccess.DeleteSingleByIdGuid(id);
241 241
         }
242 242
 
243 243
         public LuResult<TDboRead> DeleteSingleByIdDbo(string id)
244 244
         {
245
-            return NextCrud.DeleteSingleByIdDbo(id);
245
+            return DataAccess.DeleteSingleByIdDbo(id);
246 246
         }
247 247
 
248 248
         public LuResult<T> DeleteSingleById<T>(long id, Func<TDboRead, T> returnFunc)
249 249
         {
250
-            return NextCrud.DeleteSingleById(id, returnFunc);
250
+            return DataAccess.DeleteSingleById(id, returnFunc);
251 251
         }
252 252
 
253 253
         public LuResult<long> DeleteSingleByIdId(long id)
254 254
         {
255
-            return NextCrud.DeleteSingleByIdId(id);
255
+            return DataAccess.DeleteSingleByIdId(id);
256 256
         }
257 257
 
258 258
         public LuResult<TDboRead> DeleteSingleByIdDbo(long id)
259 259
         {
260
-            return NextCrud.DeleteSingleByIdDbo(id);
260
+            return DataAccess.DeleteSingleByIdDbo(id);
261 261
         }
262 262
     }
263 263
 }

+ 55
- 0
Luticate2.Utils/Controllers/LuCrudController.cs View File

@@ -0,0 +1,55 @@
1
+using Luticate2.Utils.Dbo;
2
+using Luticate2.Utils.Dbo.OrderBy;
3
+using Luticate2.Utils.Interfaces;
4
+using Microsoft.AspNetCore.Mvc;
5
+
6
+namespace Luticate2.Utils.Controllers
7
+{
8
+    public abstract class LuCrudController<TDboCreate, TDboRead, TDboUpdate> : LuController
9
+        where TDboCreate : class
10
+        where TDboRead : class
11
+        where TDboUpdate : class
12
+    {
13
+        protected readonly ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate> Busines;
14
+
15
+        protected LuCrudController(ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate> busines)
16
+        {
17
+            Busines = busines;
18
+        }
19
+
20
+        [HttpGet]
21
+        [Route("[controller]/{id}")]
22
+        public TDboRead GetSingleById(string id)
23
+        {
24
+            return Handle(Busines.GetSingleById(id));
25
+        }
26
+
27
+        [HttpGet]
28
+        [Route("[controller]")]
29
+        public LuPaginatedDbo<TDboRead> GetMultiple(LuOrderByDbo orderBy, int page = 0, int perPage = int.MaxValue)
30
+        {
31
+            return Handle(Busines.GetMultiple(orderBy, page, perPage));
32
+        }
33
+
34
+        [HttpPost]
35
+        [Route("[controller]")]
36
+        public TDboRead Add([FromBody]TDboCreate data)
37
+        {
38
+            return Handle(Busines.AddDbo(data));
39
+        }
40
+
41
+        [HttpPost]
42
+        [Route("[controller]/{id}")]
43
+        public TDboRead Edit(string id, [FromBody]TDboUpdate data)
44
+        {
45
+            return Handle(Busines.EditSingleByIdDbo(id, data));
46
+        }
47
+
48
+        [HttpDelete]
49
+        [Route("[controller]/{id}")]
50
+        public TDboRead Delete(string id)
51
+        {
52
+            return Handle(Busines.DeleteSingleByIdDbo(id));
53
+        }
54
+    }
55
+}

+ 1
- 1
WebTest/Business/PkGuidBusiness.cs View File

@@ -7,7 +7,7 @@ namespace WebTest.Business
7 7
 {
8 8
     public class PkGuidBusiness : LuCrudBusiness<LuUtilsPkGuidDataAccess, PkGuidAddDbo, PkGuidDbo, PkGuidAddDbo>
9 9
     {
10
-        public PkGuidBusiness(LuUtilsPkGuidDataAccess nextCrud) : base(nextCrud)
10
+        public PkGuidBusiness(LuUtilsPkGuidDataAccess dataAccess) : base(dataAccess)
11 11
         {
12 12
         }
13 13
 

+ 2
- 43
WebTest/Controllers/PkGuidController.cs View File

@@ -1,54 +1,13 @@
1 1
 using Luticate2.Utils.Controllers;
2
-using Luticate2.Utils.Dbo;
3
-using Luticate2.Utils.Dbo.OrderBy;
4
-using Microsoft.AspNetCore.Mvc;
5 2
 using Test.Utils.Dbo.PkGuid;
6 3
 using WebTest.Business;
7 4
 
8 5
 namespace WebTest.Controllers
9 6
 {
10
-    public class PkGuidController : LuController
7
+    public class PkGuidController : LuCrudController<PkGuidAddDbo, PkGuidDbo, PkGuidAddDbo>
11 8
     {
12
-        private readonly PkGuidBusiness _busines;
13
-
14
-        public PkGuidController(PkGuidBusiness busines)
15
-        {
16
-            _busines = busines;
17
-        }
18
-
19
-        [HttpGet]
20
-        [Route("[controller]/{id}")]
21
-        public PkGuidDbo GetSingleById(string id)
22
-        {
23
-            return Handle(_busines.GetSingleById(id));
24
-        }
25
-
26
-        [HttpGet]
27
-        [Route("[controller]")]
28
-        public LuPaginatedDbo<PkGuidDbo> GetMultiple(LuOrderByDbo orderBy, int page = 0, int perPage = int.MaxValue)
29
-        {
30
-            return Handle(_busines.GetMultiple(orderBy, page, perPage));
31
-        }
32
-
33
-        [HttpPost]
34
-        [Route("[controller]")]
35
-        public PkGuidDbo Add([FromBody]PkGuidAddDbo data)
36
-        {
37
-            return Handle(_busines.AddDbo(data));
38
-        }
39
-
40
-        [HttpPost]
41
-        [Route("[controller]/{id}")]
42
-        public PkGuidDbo Edit(string id, [FromBody]PkGuidAddDbo data)
43
-        {
44
-            return Handle(_busines.EditSingleByIdDbo(id, data));
45
-        }
46
-
47
-        [HttpDelete]
48
-        [Route("[controller]/{id}")]
49
-        public PkGuidDbo Delete(string id)
9
+        public PkGuidController(PkGuidBusiness busines) : base(busines)
50 10
         {
51
-            return Handle(_busines.DeleteSingleByIdDbo(id));
52 11
         }
53 12
     }
54 13
 }

Loading…
Cancel
Save