|
@@ -91,23 +91,23 @@ namespace Luticate2.Utils.DataAccess
|
91
|
91
|
return table;
|
92
|
92
|
}
|
93
|
93
|
|
94
|
|
- protected Func<TDboRead, T> GetIdFunc<T>()
|
|
94
|
+ protected virtual Func<TDboRead, T> GetIdFunc<T>()
|
95
|
95
|
{
|
96
|
96
|
return x => ((dynamic) x).Id;
|
97
|
97
|
}
|
98
|
98
|
|
99
|
|
- protected TModel GetModelFromTUpdate(TDboUpdate obj, TModel model)
|
|
99
|
+ protected virtual TModel GetModelFromTUpdate(TDboUpdate obj, TModel model)
|
100
|
100
|
{
|
101
|
101
|
EditModelFromTUpdate(obj, model);
|
102
|
102
|
return model;
|
103
|
103
|
}
|
104
|
104
|
|
105
|
|
- protected LuResult<T> GetNotFoundResult<T>()
|
|
105
|
+ protected virtual LuResult<T> GetNotFoundResult<T>()
|
106
|
106
|
{
|
107
|
107
|
return LuResult<T>.Error(LuStatus.NotFound, typeof(TModel).Name + ": Value not found", "");
|
108
|
108
|
}
|
109
|
109
|
|
110
|
|
- protected IQueryable<TModel> GetFilterQuery(LuFilterDbo filter, TDbContext db, DbSet<TModel> table)
|
|
110
|
+ protected virtual IQueryable<TModel> GetFilterQuery(LuFilterDbo filter, TDbContext db, DbSet<TModel> table)
|
111
|
111
|
{
|
112
|
112
|
return GetGetQueryable(db, table).Where(GetFilterExpression(filter));
|
113
|
113
|
}
|
|
@@ -115,7 +115,7 @@ namespace Luticate2.Utils.DataAccess
|
115
|
115
|
|
116
|
116
|
|
117
|
117
|
|
118
|
|
- public LuResult<T> Add<T>(IEnumerable<TDboCreate> objs, Func<IEnumerable<TDboRead>, T> returnFunc)
|
|
118
|
+ public virtual LuResult<T> Add<T>(IEnumerable<TDboCreate> objs, Func<IEnumerable<TDboRead>, T> returnFunc)
|
119
|
119
|
{
|
120
|
120
|
var models = objs.Select(GetModelFromTCreate).ToList();
|
121
|
121
|
var addRes = Execute((db, table) =>
|
|
@@ -135,30 +135,30 @@ namespace Luticate2.Utils.DataAccess
|
135
|
135
|
return GetMultiple(models, returnFunc);
|
136
|
136
|
}
|
137
|
137
|
|
138
|
|
- public LuResult<T> Add<T>(TDboCreate obj, Func<TDboRead, T> returnFunc)
|
|
138
|
+ public virtual LuResult<T> Add<T>(TDboCreate obj, Func<TDboRead, T> returnFunc)
|
139
|
139
|
{
|
140
|
140
|
return Add(new List<TDboCreate> {obj}, list => returnFunc(list.First()));
|
141
|
141
|
}
|
142
|
142
|
|
143
|
143
|
|
144
|
|
- public LuResult<IEnumerable<TId>> AddId(IEnumerable<TDboCreate> objs)
|
|
144
|
+ public virtual LuResult<IEnumerable<TId>> AddId(IEnumerable<TDboCreate> objs)
|
145
|
145
|
{
|
146
|
146
|
var func = GetIdFunc<TId>();
|
147
|
147
|
return Add(objs, list => list.Select(func));
|
148
|
148
|
}
|
149
|
149
|
|
150
|
|
- public LuResult<TId> AddId(TDboCreate obj)
|
|
150
|
+ public virtual LuResult<TId> AddId(TDboCreate obj)
|
151
|
151
|
{
|
152
|
152
|
return AddId(new List<TDboCreate> {obj}).To(list => list.First());
|
153
|
153
|
}
|
154
|
154
|
|
155
|
155
|
|
156
|
|
- public LuResult<IEnumerable<TDboRead>> AddDbo(IEnumerable<TDboCreate> obj)
|
|
156
|
+ public virtual LuResult<IEnumerable<TDboRead>> AddDbo(IEnumerable<TDboCreate> obj)
|
157
|
157
|
{
|
158
|
158
|
return Add(obj, read => read);
|
159
|
159
|
}
|
160
|
160
|
|
161
|
|
- public LuResult<TDboRead> AddDbo(TDboCreate obj)
|
|
161
|
+ public virtual LuResult<TDboRead> AddDbo(TDboCreate obj)
|
162
|
162
|
{
|
163
|
163
|
return AddDbo(new List<TDboCreate> {obj}).To(list => list.First());
|
164
|
164
|
}
|
|
@@ -166,7 +166,7 @@ namespace Luticate2.Utils.DataAccess
|
166
|
166
|
|
167
|
167
|
|
168
|
168
|
|
169
|
|
- public LuResult<TDboRead> GetSingle(Expression<Func<TModel, bool>> predicate)
|
|
169
|
+ public virtual LuResult<TDboRead> GetSingle(Expression<Func<TModel, bool>> predicate)
|
170
|
170
|
{
|
171
|
171
|
return Execute((db, table) =>
|
172
|
172
|
{
|
|
@@ -180,12 +180,12 @@ namespace Luticate2.Utils.DataAccess
|
180
|
180
|
});
|
181
|
181
|
}
|
182
|
182
|
|
183
|
|
- public LuResult<TDboRead> GetSingleByKeys(params KeyValuePair<string, object>[] keys)
|
|
183
|
+ public virtual LuResult<TDboRead> GetSingleByKeys(params KeyValuePair<string, object>[] keys)
|
184
|
184
|
{
|
185
|
185
|
return GetSingle(GetExpression(keys));
|
186
|
186
|
}
|
187
|
187
|
|
188
|
|
- public LuResult<TDboRead> GetSingleById(TId id)
|
|
188
|
+ public virtual LuResult<TDboRead> GetSingleById(TId id)
|
189
|
189
|
{
|
190
|
190
|
var guid = GetId(id);
|
191
|
191
|
if (guid == null)
|
|
@@ -195,7 +195,7 @@ namespace Luticate2.Utils.DataAccess
|
195
|
195
|
return GetSingleByKeys(new KeyValuePair<string, object>("id", guid));
|
196
|
196
|
}
|
197
|
197
|
|
198
|
|
- protected LuResult<T> GetMultiple<T>(IList<TModel> models, Func<IEnumerable<TDboRead>, T> returnFunc)
|
|
198
|
+ protected virtual LuResult<T> GetMultiple<T>(IList<TModel> models, Func<IEnumerable<TDboRead>, T> returnFunc)
|
199
|
199
|
{
|
200
|
200
|
var dbos = new List<TDboRead>();
|
201
|
201
|
foreach (var model in models)
|
|
@@ -211,7 +211,7 @@ namespace Luticate2.Utils.DataAccess
|
211
|
211
|
return LuResult<T>.Ok(res);
|
212
|
212
|
}
|
213
|
213
|
|
214
|
|
- public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(Func<IQueryable<TModel>, IOrderedQueryable<TModel>> orderBy,
|
|
214
|
+ public virtual LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(Func<IQueryable<TModel>, IOrderedQueryable<TModel>> orderBy,
|
215
|
215
|
Expression<Func<TModel, bool>> predicate, int page = 0, int perPage = int.MaxValue,
|
216
|
216
|
params Func<IOrderedQueryable<TModel>, IOrderedQueryable<TModel>>[] otherOrderBy)
|
217
|
217
|
{
|
|
@@ -234,7 +234,7 @@ namespace Luticate2.Utils.DataAccess
|
234
|
234
|
});
|
235
|
235
|
}
|
236
|
236
|
|
237
|
|
- public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(Expression<Func<TModel, object>> orderBy,
|
|
237
|
+ public virtual LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(Expression<Func<TModel, object>> orderBy,
|
238
|
238
|
Expression<Func<TModel, bool>> predicate, int page = 0, int perPage = int.MaxValue,
|
239
|
239
|
params Expression<Func<TModel, object>>[] otherOrderBy)
|
240
|
240
|
{
|
|
@@ -243,19 +243,19 @@ namespace Luticate2.Utils.DataAccess
|
243
|
243
|
IOrderedQueryable<TModel>>>(expression => (t => t.ThenBy(expression))).ToArray());
|
244
|
244
|
}
|
245
|
245
|
|
246
|
|
- public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(Func<IQueryable<TModel>, IOrderedQueryable<TModel>> orderBy,
|
|
246
|
+ public virtual LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(Func<IQueryable<TModel>, IOrderedQueryable<TModel>> orderBy,
|
247
|
247
|
int page = 0, int perPage = int.MaxValue, params Func<IOrderedQueryable<TModel>, IOrderedQueryable<TModel>>[] otherOrderBy)
|
248
|
248
|
{
|
249
|
249
|
return GetMultiple(orderBy, x => true, page, perPage, otherOrderBy);
|
250
|
250
|
}
|
251
|
251
|
|
252
|
|
- public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(Expression<Func<TModel, object>> orderBy,
|
|
252
|
+ public virtual LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(Expression<Func<TModel, object>> orderBy,
|
253
|
253
|
int page = 0, int perPage = int.MaxValue, params Expression<Func<TModel, object>>[] otherOrderBy)
|
254
|
254
|
{
|
255
|
255
|
return GetMultiple(orderBy, x => true, page, perPage, otherOrderBy);
|
256
|
256
|
}
|
257
|
257
|
|
258
|
|
- public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, Func<TDbContext, DbSet<TModel>, IQueryable<TModel>> getQueryable,
|
|
258
|
+ public virtual LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, Func<TDbContext, DbSet<TModel>, IQueryable<TModel>> getQueryable,
|
259
|
259
|
int page = 0, int perPage = int.MaxValue)
|
260
|
260
|
{
|
261
|
261
|
return Execute((db, table) =>
|
|
@@ -291,20 +291,20 @@ namespace Luticate2.Utils.DataAccess
|
291
|
291
|
});
|
292
|
292
|
}
|
293
|
293
|
|
294
|
|
- public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, LuFilterDbo filter,
|
|
294
|
+ public virtual LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, LuFilterDbo filter,
|
295
|
295
|
int page = 0, int perPage = int.MaxValue)
|
296
|
296
|
{
|
297
|
297
|
return GetMultiple(orderBy, (db, table) => GetFilterQuery(filter, db, table), page, perPage);
|
298
|
298
|
}
|
299
|
299
|
|
300
|
|
- public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, int page = 0, int perPage = int.MaxValue)
|
|
300
|
+ public virtual LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, int page = 0, int perPage = int.MaxValue)
|
301
|
301
|
{
|
302
|
302
|
return GetMultiple(orderBy, GetGetQueryable, page, perPage);
|
303
|
303
|
}
|
304
|
304
|
|
305
|
305
|
|
306
|
306
|
|
307
|
|
- public LuResult<T> Edit<T>(Expression<Func<TModel, bool>> predicate, Action<TModel> update,
|
|
307
|
+ public virtual LuResult<T> Edit<T>(Expression<Func<TModel, bool>> predicate, Action<TModel> update,
|
308
|
308
|
Func<IEnumerable<TDboRead>, T> returnFunc)
|
309
|
309
|
{
|
310
|
310
|
IList<TModel> models = null;
|
|
@@ -326,19 +326,19 @@ namespace Luticate2.Utils.DataAccess
|
326
|
326
|
return GetMultiple(models, returnFunc);
|
327
|
327
|
}
|
328
|
328
|
|
329
|
|
- public LuResult<IEnumerable<TId>> EditId(Expression<Func<TModel, bool>> predicate, Action<TModel> update)
|
|
329
|
+ public virtual LuResult<IEnumerable<TId>> EditId(Expression<Func<TModel, bool>> predicate, Action<TModel> update)
|
330
|
330
|
{
|
331
|
331
|
var func = GetIdFunc<TId>();
|
332
|
332
|
return Edit(predicate, update, reads => reads.Select(func));
|
333
|
333
|
}
|
334
|
334
|
|
335
|
|
- public LuResult<IEnumerable<TDboRead>> EditDbo(Expression<Func<TModel, bool>> predicate, Action<TModel> update)
|
|
335
|
+ public virtual LuResult<IEnumerable<TDboRead>> EditDbo(Expression<Func<TModel, bool>> predicate, Action<TModel> update)
|
336
|
336
|
{
|
337
|
337
|
return Edit(predicate, update, read => read);
|
338
|
338
|
}
|
339
|
339
|
|
340
|
340
|
|
341
|
|
- public LuResult<T> EditSingleById<T>(TId id, Action<TModel> update, Func<TDboRead, T> returnFunc)
|
|
341
|
+ public virtual LuResult<T> EditSingleById<T>(TId id, Action<TModel> update, Func<TDboRead, T> returnFunc)
|
342
|
342
|
{
|
343
|
343
|
var guid = GetId(id);
|
344
|
344
|
if (guid == null)
|
|
@@ -349,18 +349,18 @@ namespace Luticate2.Utils.DataAccess
|
349
|
349
|
list => returnFunc(list.FirstOrDefault()));
|
350
|
350
|
}
|
351
|
351
|
|
352
|
|
- public LuResult<TId> EditSingleByIdId(TId id, Action<TModel> update)
|
|
352
|
+ public virtual LuResult<TId> EditSingleByIdId(TId id, Action<TModel> update)
|
353
|
353
|
{
|
354
|
354
|
return EditSingleById(id, update, GetIdFunc<TId>());
|
355
|
355
|
}
|
356
|
356
|
|
357
|
|
- public LuResult<TDboRead> EditSingleByIdDbo(TId id, Action<TModel> update)
|
|
357
|
+ public virtual LuResult<TDboRead> EditSingleByIdDbo(TId id, Action<TModel> update)
|
358
|
358
|
{
|
359
|
359
|
return EditSingleById(id, update, read => read);
|
360
|
360
|
}
|
361
|
361
|
|
362
|
362
|
|
363
|
|
- public LuResult<T> EditSingleById<T>(TId id, TDboUpdate update, Func<TDboRead, T> returnFunc)
|
|
363
|
+ public virtual LuResult<T> EditSingleById<T>(TId id, TDboUpdate update, Func<TDboRead, T> returnFunc)
|
364
|
364
|
{
|
365
|
365
|
var guid = GetId(id);
|
366
|
366
|
if (guid == null)
|
|
@@ -371,12 +371,12 @@ namespace Luticate2.Utils.DataAccess
|
371
|
371
|
model => EditModelFromTUpdate(update, model), list => returnFunc(list.FirstOrDefault()));
|
372
|
372
|
}
|
373
|
373
|
|
374
|
|
- public LuResult<TId> EditSingleByIdId(TId id, TDboUpdate update)
|
|
374
|
+ public virtual LuResult<TId> EditSingleByIdId(TId id, TDboUpdate update)
|
375
|
375
|
{
|
376
|
376
|
return EditSingleById(id, update, GetIdFunc<TId>());
|
377
|
377
|
}
|
378
|
378
|
|
379
|
|
- public LuResult<TDboRead> EditSingleByIdDbo(TId id, TDboUpdate update)
|
|
379
|
+ public virtual LuResult<TDboRead> EditSingleByIdDbo(TId id, TDboUpdate update)
|
380
|
380
|
{
|
381
|
381
|
return EditSingleById(id, update, read => read);
|
382
|
382
|
}
|
|
@@ -384,7 +384,7 @@ namespace Luticate2.Utils.DataAccess
|
384
|
384
|
|
385
|
385
|
|
386
|
386
|
|
387
|
|
- public LuResult<T> Delete<T>(Expression<Func<TModel, bool>> predicate,
|
|
387
|
+ public virtual LuResult<T> Delete<T>(Expression<Func<TModel, bool>> predicate,
|
388
|
388
|
Func<IEnumerable<TDboRead>, T> returnFunc)
|
389
|
389
|
{
|
390
|
390
|
return Execute((db, table) =>
|
|
@@ -401,19 +401,19 @@ namespace Luticate2.Utils.DataAccess
|
401
|
401
|
});
|
402
|
402
|
}
|
403
|
403
|
|
404
|
|
- public LuResult<IEnumerable<TId>> DeleteId(Expression<Func<TModel, bool>> predicate)
|
|
404
|
+ public virtual LuResult<IEnumerable<TId>> DeleteId(Expression<Func<TModel, bool>> predicate)
|
405
|
405
|
{
|
406
|
406
|
var func = GetIdFunc<TId>();
|
407
|
407
|
return Delete(predicate, reads => reads.Select(func));
|
408
|
408
|
}
|
409
|
409
|
|
410
|
|
- public LuResult<IEnumerable<TDboRead>> DeleteDbo(Expression<Func<TModel, bool>> predicate)
|
|
410
|
+ public virtual LuResult<IEnumerable<TDboRead>> DeleteDbo(Expression<Func<TModel, bool>> predicate)
|
411
|
411
|
{
|
412
|
412
|
return Delete(predicate, read => read);
|
413
|
413
|
}
|
414
|
414
|
|
415
|
415
|
|
416
|
|
- public LuResult<T> DeleteSingleById<T>(TId id, Func<TDboRead, T> returnFunc)
|
|
416
|
+ public virtual LuResult<T> DeleteSingleById<T>(TId id, Func<TDboRead, T> returnFunc)
|
417
|
417
|
{
|
418
|
418
|
var guid = GetId(id);
|
419
|
419
|
if (guid == null)
|
|
@@ -424,13 +424,13 @@ namespace Luticate2.Utils.DataAccess
|
424
|
424
|
reads => returnFunc(reads.FirstOrDefault()));
|
425
|
425
|
}
|
426
|
426
|
|
427
|
|
- public LuResult<TId> DeleteSingleByIdId(TId id)
|
|
427
|
+ public virtual LuResult<TId> DeleteSingleByIdId(TId id)
|
428
|
428
|
{
|
429
|
429
|
var func = GetIdFunc<TId>();
|
430
|
430
|
return DeleteSingleById(id, func);
|
431
|
431
|
}
|
432
|
432
|
|
433
|
|
- public LuResult<TDboRead> DeleteSingleByIdDbo(TId id)
|
|
433
|
+ public virtual LuResult<TDboRead> DeleteSingleByIdDbo(TId id)
|
434
|
434
|
{
|
435
|
435
|
return DeleteSingleById(id, read => read);
|
436
|
436
|
}
|