|
@@ -40,7 +40,7 @@ namespace Luticate2.Auth.Utils.DataAccess.Crud
|
40
|
40
|
};
|
41
|
41
|
}
|
42
|
42
|
|
43
|
|
- protected virtual LuResult<TTypeTo> Convert<TTypeTo>(LuPartialFieldsDbo partialInput, object dbo, LuConvertersOptions options) where TTypeTo : class
|
|
43
|
+ protected virtual LuResult<TTypeTo> Convert<TTypeTo>(LuPartialFieldsDbo partialResponse, object dbo, LuConvertersOptions options) where TTypeTo : class
|
44
|
44
|
{
|
45
|
45
|
var typeTo = dbo.GetType();
|
46
|
46
|
var converterType = typeof(ILuObjectConverter<,>);
|
|
@@ -58,10 +58,28 @@ namespace Luticate2.Auth.Utils.DataAccess.Crud
|
58
|
58
|
return dstObjResult.To<TTypeTo>();
|
59
|
59
|
}
|
60
|
60
|
var dstObj = dstObjResult.Data;
|
61
|
|
- var result = converter.Convert(dbo, dstObj, new LuFieldDbo(), partialInput, options);
|
|
61
|
+ var result = converter.Convert(dbo, dstObj, new LuFieldDbo(), partialResponse, options);
|
62
|
62
|
return result.Select(o => o as TTypeTo);
|
63
|
63
|
}
|
64
|
64
|
|
|
65
|
+ protected virtual LuResult<IList<TTypeTo>> Convert<TTypeTo>(LuPartialFieldsDbo partialResponse, IEnumerable<object> dbos, LuConvertersOptions options) where TTypeTo : class
|
|
66
|
+ {
|
|
67
|
+ var dboList = new List<TTypeTo>();
|
|
68
|
+ foreach (var model in dbos)
|
|
69
|
+ {
|
|
70
|
+ var dboResult = Convert<TTypeTo>(partialResponse, model, options);
|
|
71
|
+ if (!dboResult)
|
|
72
|
+ {
|
|
73
|
+ return dboResult.To<IList<TTypeTo>>();
|
|
74
|
+ }
|
|
75
|
+ var dbo = dboResult.Data;
|
|
76
|
+
|
|
77
|
+ dboList.Add(dbo);
|
|
78
|
+ }
|
|
79
|
+
|
|
80
|
+ return LuResult<IList<TTypeTo>>.Ok(dboList);
|
|
81
|
+ }
|
|
82
|
+
|
65
|
83
|
protected virtual LuResult<T> HandleError<T>(Exception e)
|
66
|
84
|
{
|
67
|
85
|
return LuResult<T>.Error(LuStatus.DbError.ToInt(), e);
|
|
@@ -161,6 +179,46 @@ namespace Luticate2.Auth.Utils.DataAccess.Crud
|
161
|
179
|
return LuResult<IQueryable<TModel>>.Ok(paginated);
|
162
|
180
|
}
|
163
|
181
|
|
|
182
|
+ protected virtual LuResult<LuPaginatedDbo<TModel>> Paginate(LuPaginatedParamsDbo paginationParams, LuPartialFieldsDbo partialResponse, IQueryable<TModel> set, LuConvertersOptions options)
|
|
183
|
+ {
|
|
184
|
+ var includeResult = Include(partialResponse, set);
|
|
185
|
+ if (!includeResult)
|
|
186
|
+ {
|
|
187
|
+ return includeResult.To<LuPaginatedDbo<TModel>>();
|
|
188
|
+ }
|
|
189
|
+ var included = includeResult.Data;
|
|
190
|
+
|
|
191
|
+ var orderByResult = OrderBy(paginationParams.OrderBy, included, options);
|
|
192
|
+ if (!orderByResult)
|
|
193
|
+ {
|
|
194
|
+ return orderByResult.To<LuPaginatedDbo<TModel>>();
|
|
195
|
+ }
|
|
196
|
+ var ordered = orderByResult.Data;
|
|
197
|
+
|
|
198
|
+ var filteredResult = Filter(paginationParams.Filter, ordered, options);
|
|
199
|
+ if (!filteredResult)
|
|
200
|
+ {
|
|
201
|
+ return filteredResult.To<LuPaginatedDbo<TModel>>();
|
|
202
|
+ }
|
|
203
|
+ var filtered = filteredResult.Data;
|
|
204
|
+ var count = filtered.Count();
|
|
205
|
+
|
|
206
|
+ var paginatedResult = Paginate(paginationParams.Page, paginationParams.PerPage, filtered);
|
|
207
|
+ if (!paginatedResult)
|
|
208
|
+ {
|
|
209
|
+ return paginatedResult.To<LuPaginatedDbo<TModel>>();
|
|
210
|
+ }
|
|
211
|
+ var paginated = paginatedResult.Data;
|
|
212
|
+
|
|
213
|
+ var paginatedData = new LuPaginatedDbo<TModel>
|
|
214
|
+ {
|
|
215
|
+ Data = paginated.ToList(),
|
|
216
|
+ Count = count
|
|
217
|
+ };
|
|
218
|
+
|
|
219
|
+ return LuResult<LuPaginatedDbo<TModel>>.Ok(paginatedData);
|
|
220
|
+ }
|
|
221
|
+
|
164
|
222
|
public virtual LuResult<IList<TDbo>> Create(LuPartialFieldsDbo partialResponse, LuPartialFieldsDbo partialInput, IEnumerable<object> dbos)
|
165
|
223
|
{
|
166
|
224
|
var options = GetOptions();
|
|
@@ -210,65 +268,69 @@ namespace Luticate2.Auth.Utils.DataAccess.Crud
|
210
|
268
|
{
|
211
|
269
|
var options = GetOptions();
|
212
|
270
|
|
213
|
|
- var includeResult = Include(partialResponse, set);
|
214
|
|
- if (!includeResult)
|
215
|
|
- {
|
216
|
|
- return includeResult.To<LuPaginatedDbo<TDbo>>();
|
217
|
|
- }
|
218
|
|
- var included = includeResult.Data;
|
219
|
|
-
|
220
|
|
- var orderByResult = OrderBy(paginationParams.OrderBy, included, options);
|
221
|
|
- if (!orderByResult)
|
222
|
|
- {
|
223
|
|
- return orderByResult.To<LuPaginatedDbo<TDbo>>();
|
224
|
|
- }
|
225
|
|
- var ordered = orderByResult.Data;
|
226
|
|
-
|
227
|
|
- var filteredResult = Filter(paginationParams.Filter, ordered, options);
|
228
|
|
- if (!filteredResult)
|
229
|
|
- {
|
230
|
|
- return filteredResult.To<LuPaginatedDbo<TDbo>>();
|
231
|
|
- }
|
232
|
|
- var filtered = filteredResult.Data;
|
233
|
|
- var count = filtered.Count();
|
234
|
|
-
|
235
|
|
- var paginatedResult = Paginate(paginationParams.Page, paginationParams.PerPage, filtered);
|
|
271
|
+ var paginatedResult = Paginate(paginationParams, partialResponse, set, options);
|
236
|
272
|
if (!paginatedResult)
|
237
|
273
|
{
|
238
|
274
|
return paginatedResult.To<LuPaginatedDbo<TDbo>>();
|
239
|
275
|
}
|
240
|
276
|
var paginated = paginatedResult.Data;
|
241
|
277
|
|
242
|
|
- var dboList = new List<TDbo>();
|
243
|
|
- foreach (var model in paginated)
|
|
278
|
+ var dboListResult = Convert<TDbo>(partialResponse, paginated.Data, options);
|
|
279
|
+ if (!dboListResult)
|
244
|
280
|
{
|
245
|
|
- var dboResult = Convert<TDbo>(partialResponse, model, options);
|
246
|
|
- if (!dboResult)
|
247
|
|
- {
|
248
|
|
- return dboResult.To<LuPaginatedDbo<TDbo>>();
|
249
|
|
- }
|
250
|
|
- var dbo = dboResult.Data;
|
251
|
|
-
|
252
|
|
- dboList.Add(dbo);
|
|
281
|
+ return dboListResult.To<LuPaginatedDbo<TDbo>>();
|
253
|
282
|
}
|
|
283
|
+ var dboList = dboListResult.Data;
|
254
|
284
|
|
255
|
|
- return LuResult<LuPaginatedDbo<TDbo>>.Ok(new LuPaginatedDbo<TDbo>
|
|
285
|
+ var paginatedData = new LuPaginatedDbo<TDbo>
|
256
|
286
|
{
|
257
|
|
- Count = count,
|
|
287
|
+ Count = paginated.Count,
|
258
|
288
|
Data = dboList
|
259
|
|
- });
|
|
289
|
+ };
|
|
290
|
+
|
|
291
|
+ return LuResult<LuPaginatedDbo<TDbo>>.Ok(paginatedData);
|
260
|
292
|
});
|
261
|
293
|
return result;
|
262
|
294
|
}
|
263
|
295
|
|
264
|
|
- public virtual LuResult<IList<TDbo>> Update(LuPartialFieldsDbo partialResponse, LuPartialFieldsDbo partialInput, IEnumerable<TDbo> dbos)
|
|
296
|
+ public virtual LuResult<IList<TDbo>> Update(LuPartialFieldsDbo partialResponse, LuPartialFieldsDbo partialInput, IEnumerable<object> dbos)
|
265
|
297
|
{
|
266
|
298
|
throw new NotImplementedException();
|
267
|
299
|
}
|
268
|
300
|
|
269
|
|
- public virtual LuResult<IList<TDbo>> Delete(LuPartialFieldsDbo partialResponse, LuPartialFieldsDbo partialInput, IEnumerable<TDbo> dbos)
|
|
301
|
+ public virtual LuResult<LuPaginatedDbo<TDbo>> Delete(LuPartialFieldsDbo partialResponse, LuPaginatedParamsDbo paginationParams)
|
270
|
302
|
{
|
271
|
|
- throw new NotImplementedException();
|
|
303
|
+ var res = Execute((context, set) =>
|
|
304
|
+ {
|
|
305
|
+ var options = GetOptions();
|
|
306
|
+
|
|
307
|
+ var paginatedResult = Paginate(paginationParams, partialResponse, set, options);
|
|
308
|
+ if (!paginatedResult)
|
|
309
|
+ {
|
|
310
|
+ return paginatedResult.To<LuPaginatedDbo<TDbo>>();
|
|
311
|
+ }
|
|
312
|
+ var paginated = paginatedResult.Data;
|
|
313
|
+
|
|
314
|
+ var dboListResult = Convert<TDbo>(partialResponse, paginated.Data, options);
|
|
315
|
+ if (!dboListResult)
|
|
316
|
+ {
|
|
317
|
+ return dboListResult.To<LuPaginatedDbo<TDbo>>();
|
|
318
|
+ }
|
|
319
|
+ var dboList = dboListResult.Data;
|
|
320
|
+
|
|
321
|
+ set.RemoveRange(paginated.Data);
|
|
322
|
+ context.SaveChanges();
|
|
323
|
+
|
|
324
|
+ var paginatedData = new LuPaginatedDbo<TDbo>
|
|
325
|
+ {
|
|
326
|
+ Count = paginated.Count,
|
|
327
|
+ Data = dboList
|
|
328
|
+ };
|
|
329
|
+
|
|
330
|
+ return LuResult<LuPaginatedDbo<TDbo>>.Ok(paginatedData);
|
|
331
|
+ });
|
|
332
|
+
|
|
333
|
+ return res;
|
272
|
334
|
}
|
273
|
335
|
}
|
274
|
336
|
}
|