Browse Source

curd business checks; TODO

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

+ 92
- 1
Luticate2.Utils/Business/LuCrudBusiness.cs View File

46
             return LuResult<TDboUpdate>.Ok(update);
46
             return LuResult<TDboUpdate>.Ok(update);
47
         }
47
         }
48
 
48
 
49
+        protected virtual LuResult<TDboRead> CheckGet(TDboRead obj)
50
+        {
51
+            return LuResult<TDboRead>.Ok(obj);
52
+        }
53
+
54
+        protected virtual LuResult<TDboRead> CheckDelete(TDboRead obj)
55
+        {
56
+            return LuResult<TDboRead>.Ok(obj);
57
+        }
58
+
49
         protected LuResult<TDboUpdate> GetAndCheckEdit(string id, TDboUpdate update)
59
         protected LuResult<TDboUpdate> GetAndCheckEdit(string id, TDboUpdate update)
50
         {
60
         {
51
             var res = GetSingleById(id);
61
             var res = GetSingleById(id);
66
             return CheckEdit(res.Data, update);
76
             return CheckEdit(res.Data, update);
67
         }
77
         }
68
 
78
 
79
+        protected LuResult<TDboRead> GetAndCheckGet(string id)
80
+        {
81
+            var res = GetSingleById(id);
82
+            if (!res)
83
+            {
84
+                return res.To<TDboRead>();
85
+            }
86
+            return CheckGet(res.Data);
87
+        }
88
+
89
+        protected LuResult<TDboRead> GetAndCheckGet(long id)
90
+        {
91
+            var res = GetSingleById(id);
92
+            if (!res)
93
+            {
94
+                return res.To<TDboRead>();
95
+            }
96
+            return CheckGet(res.Data);
97
+        }
98
+
99
+        protected LuResult<TDboRead> GetAndCheckDelete(string id)
100
+        {
101
+            var res = GetSingleById(id);
102
+            if (!res)
103
+            {
104
+                return res.To<TDboRead>();
105
+            }
106
+            return CheckDelete(res.Data);
107
+        }
108
+
109
+        protected LuResult<TDboRead> GetAndCheckDelete(long id)
110
+        {
111
+            var res = GetSingleById(id);
112
+            if (!res)
113
+            {
114
+                return res.To<TDboRead>();
115
+            }
116
+            return CheckDelete(res.Data);
117
+        }
118
+
69
 
119
 
70
 
120
 
71
         public LuResult<T> Add<T>(IEnumerable<TDboCreate> objs, Func<IEnumerable<TDboRead>, T> returnFunc)
121
         public LuResult<T> Add<T>(IEnumerable<TDboCreate> objs, Func<IEnumerable<TDboRead>, T> returnFunc)
153
 
203
 
154
         public LuResult<TDboRead> GetSingleById(string id)
204
         public LuResult<TDboRead> GetSingleById(string id)
155
         {
205
         {
206
+            var res = GetAndCheckGet(id);
207
+            if (!res)
208
+            {
209
+                return res.To<TDboRead>();
210
+            }
156
             return DataAccess.GetSingleById(id);
211
             return DataAccess.GetSingleById(id);
157
         }
212
         }
158
 
213
 
159
         public LuResult<TDboRead> GetSingleById(long id)
214
         public LuResult<TDboRead> GetSingleById(long id)
160
         {
215
         {
216
+            var res = GetAndCheckGet(id);
217
+            if (!res)
218
+            {
219
+                return res.To<TDboRead>();
220
+            }
161
             return DataAccess.GetSingleById(id);
221
             return DataAccess.GetSingleById(id);
162
         }
222
         }
163
 
223
 
164
-        public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, int page = 0, int perPage = int.MaxValue)
224
+        public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, int page = 0,
225
+            int perPage = int.MaxValue)
165
         {
226
         {
166
             return DataAccess.GetMultiple(orderBy, 0, perPage);
227
             return DataAccess.GetMultiple(orderBy, 0, perPage);
167
         }
228
         }
234
 
295
 
235
         public LuResult<T> DeleteSingleById<T>(string id, Func<TDboRead, T> returnFunc)
296
         public LuResult<T> DeleteSingleById<T>(string id, Func<TDboRead, T> returnFunc)
236
         {
297
         {
298
+            var res = GetAndCheckDelete(id);
299
+            if (!res)
300
+            {
301
+                return res.To<T>();
302
+            }
237
             return DataAccess.DeleteSingleById(id, returnFunc);
303
             return DataAccess.DeleteSingleById(id, returnFunc);
238
         }
304
         }
239
 
305
 
240
         public LuResult<string> DeleteSingleByIdGuid(string id)
306
         public LuResult<string> DeleteSingleByIdGuid(string id)
241
         {
307
         {
308
+            var res = GetAndCheckDelete(id);
309
+            if (!res)
310
+            {
311
+                return res.To<string>();
312
+            }
242
             return DataAccess.DeleteSingleByIdGuid(id);
313
             return DataAccess.DeleteSingleByIdGuid(id);
243
         }
314
         }
244
 
315
 
245
         public LuResult<TDboRead> DeleteSingleByIdDbo(string id)
316
         public LuResult<TDboRead> DeleteSingleByIdDbo(string id)
246
         {
317
         {
318
+            var res = GetAndCheckDelete(id);
319
+            if (!res)
320
+            {
321
+                return res.To<TDboRead>();
322
+            }
247
             return DataAccess.DeleteSingleByIdDbo(id);
323
             return DataAccess.DeleteSingleByIdDbo(id);
248
         }
324
         }
249
 
325
 
250
         public LuResult<T> DeleteSingleById<T>(long id, Func<TDboRead, T> returnFunc)
326
         public LuResult<T> DeleteSingleById<T>(long id, Func<TDboRead, T> returnFunc)
251
         {
327
         {
328
+            var res = GetAndCheckDelete(id);
329
+            if (!res)
330
+            {
331
+                return res.To<T>();
332
+            }
252
             return DataAccess.DeleteSingleById(id, returnFunc);
333
             return DataAccess.DeleteSingleById(id, returnFunc);
253
         }
334
         }
254
 
335
 
255
         public LuResult<long> DeleteSingleByIdId(long id)
336
         public LuResult<long> DeleteSingleByIdId(long id)
256
         {
337
         {
338
+            var res = GetAndCheckDelete(id);
339
+            if (!res)
340
+            {
341
+                return res.To<long>();
342
+            }
257
             return DataAccess.DeleteSingleByIdId(id);
343
             return DataAccess.DeleteSingleByIdId(id);
258
         }
344
         }
259
 
345
 
260
         public LuResult<TDboRead> DeleteSingleByIdDbo(long id)
346
         public LuResult<TDboRead> DeleteSingleByIdDbo(long id)
261
         {
347
         {
348
+            var res = GetAndCheckDelete(id);
349
+            if (!res)
350
+            {
351
+                return res.To<TDboRead>();
352
+            }
262
             return DataAccess.DeleteSingleByIdDbo(id);
353
             return DataAccess.DeleteSingleByIdDbo(id);
263
         }
354
         }
264
     }
355
     }

+ 1
- 1
Luticate2.Utils/Middlewares/LuExceptionMiddleware.cs View File

36
                     Message = e.Result.PublicDetails
36
                     Message = e.Result.PublicDetails
37
                 })).ConfigureAwait(false);
37
                 })).ConfigureAwait(false);
38
             }
38
             }
39
-            catch (Exception e)
39
+            catch (Exception e)//TODO
40
             {
40
             {
41
                 var response = context.Response;
41
                 var response = context.Response;
42
                 response.ContentType = "application/json";
42
                 response.ContentType = "application/json";

+ 3
- 3
TODO View File

1
 websockets
1
 websockets
2
 authentication filter
2
 authentication filter
3
-controller handle method
4
-order by dbo
5
 filter dbo
3
 filter dbo
6
-crub interface get multiple
7
 try to generify long/string id
4
 try to generify long/string id
5
+logs
6
+log exceptions in middleware
7
+LuCrudBusiness check user?

Loading…
Cancel
Save