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,6 +46,16 @@ namespace Luticate2.Utils.Business
46 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 59
         protected LuResult<TDboUpdate> GetAndCheckEdit(string id, TDboUpdate update)
50 60
         {
51 61
             var res = GetSingleById(id);
@@ -66,6 +76,46 @@ namespace Luticate2.Utils.Business
66 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 121
         public LuResult<T> Add<T>(IEnumerable<TDboCreate> objs, Func<IEnumerable<TDboRead>, T> returnFunc)
@@ -153,15 +203,26 @@ namespace Luticate2.Utils.Business
153 203
 
154 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 211
             return DataAccess.GetSingleById(id);
157 212
         }
158 213
 
159 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 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 227
             return DataAccess.GetMultiple(orderBy, 0, perPage);
167 228
         }
@@ -234,31 +295,61 @@ namespace Luticate2.Utils.Business
234 295
 
235 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 303
             return DataAccess.DeleteSingleById(id, returnFunc);
238 304
         }
239 305
 
240 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 313
             return DataAccess.DeleteSingleByIdGuid(id);
243 314
         }
244 315
 
245 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 323
             return DataAccess.DeleteSingleByIdDbo(id);
248 324
         }
249 325
 
250 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 333
             return DataAccess.DeleteSingleById(id, returnFunc);
253 334
         }
254 335
 
255 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 343
             return DataAccess.DeleteSingleByIdId(id);
258 344
         }
259 345
 
260 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 353
             return DataAccess.DeleteSingleByIdDbo(id);
263 354
         }
264 355
     }

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

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

+ 3
- 3
TODO View File

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

Loading…
Cancel
Save