Browse Source

crud interface get multiple with order by; tests

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

+ 9
- 1
Luticate2.Auth/Controllers/LuticateExtensions.cs View File

1
-using Luticate2.Auth.Business;
1
+using System.Collections.Generic;
2
+using Luticate2.Auth.Business;
2
 using Luticate2.Auth.DataAccess;
3
 using Luticate2.Auth.DataAccess;
3
 using Luticate2.Auth.Middlewares;
4
 using Luticate2.Auth.Middlewares;
5
+using Luticate2.Utils.Controllers;
4
 using Luticate2.Utils.Dbo.OrderBy;
6
 using Luticate2.Utils.Dbo.OrderBy;
5
 using Microsoft.AspNetCore.Builder;
7
 using Microsoft.AspNetCore.Builder;
8
+using Microsoft.AspNetCore.Http;
6
 using Microsoft.AspNetCore.Mvc;
9
 using Microsoft.AspNetCore.Mvc;
7
 using Microsoft.Extensions.DependencyInjection;
10
 using Microsoft.Extensions.DependencyInjection;
8
 
11
 
37
             app.UseMiddleware<LuAuthMiddleware>();
40
             app.UseMiddleware<LuAuthMiddleware>();
38
             return app;
41
             return app;
39
         }
42
         }
43
+
44
+        public static object GetLuCurrentUser(this HttpContext context)
45
+        {
46
+            return context.GetLuItems()["currentUser"];//TODO
47
+        }
40
     }
48
     }
41
 }
49
 }

+ 32
- 26
Luticate2.Utils/Business/LuCrudBusiness.cs View File

1
 using System;
1
 using System;
2
 using System.Collections.Generic;
2
 using System.Collections.Generic;
3
 using Luticate2.Utils.Dbo;
3
 using Luticate2.Utils.Dbo;
4
+using Luticate2.Utils.Dbo.OrderBy;
4
 using Luticate2.Utils.Interfaces;
5
 using Luticate2.Utils.Interfaces;
5
 
6
 
6
 namespace Luticate2.Utils.Business
7
 namespace Luticate2.Utils.Business
11
         where TDboRead : class
12
         where TDboRead : class
12
         where TDboUpdate : class
13
         where TDboUpdate : class
13
     {
14
     {
14
-        protected readonly TNextCrud Db;
15
+        protected readonly TNextCrud NextCrud;
15
 
16
 
16
-        protected LuCrudBusiness(TNextCrud db)
17
+        protected LuCrudBusiness(TNextCrud nextCrud)
17
         {
18
         {
18
-            Db = db;
19
+            NextCrud = nextCrud;
19
         }
20
         }
20
 
21
 
21
         protected virtual LuResult<TDboCreate> CheckAdd(TDboCreate obj)
22
         protected virtual LuResult<TDboCreate> CheckAdd(TDboCreate obj)
72
             {
73
             {
73
                 return res.To<T>();
74
                 return res.To<T>();
74
             }
75
             }
75
-            return Db.Add(res.Data, returnFunc);
76
+            return NextCrud.Add(res.Data, returnFunc);
76
         }
77
         }
77
 
78
 
78
         public LuResult<T> Add<T>(TDboCreate obj, Func<TDboRead, T> returnFunc)
79
         public LuResult<T> Add<T>(TDboCreate obj, Func<TDboRead, T> returnFunc)
82
             {
83
             {
83
                 return res.To<T>();
84
                 return res.To<T>();
84
             }
85
             }
85
-            return Db.Add(res.Data, returnFunc);
86
+            return NextCrud.Add(res.Data, returnFunc);
86
         }
87
         }
87
 
88
 
88
         public LuResult<IEnumerable<string>> AddGuid(IEnumerable<TDboCreate> objs)
89
         public LuResult<IEnumerable<string>> AddGuid(IEnumerable<TDboCreate> objs)
92
             {
93
             {
93
                 return res.To<IEnumerable<string>>();
94
                 return res.To<IEnumerable<string>>();
94
             }
95
             }
95
-            return Db.AddGuid(res.Data);
96
+            return NextCrud.AddGuid(res.Data);
96
         }
97
         }
97
 
98
 
98
         public LuResult<string> AddGuid(TDboCreate obj)
99
         public LuResult<string> AddGuid(TDboCreate obj)
102
             {
103
             {
103
                 return res.To<string>();
104
                 return res.To<string>();
104
             }
105
             }
105
-            return Db.AddGuid(res.Data);
106
+            return NextCrud.AddGuid(res.Data);
106
         }
107
         }
107
 
108
 
108
         public LuResult<IEnumerable<long>> AddId(IEnumerable<TDboCreate> obj)
109
         public LuResult<IEnumerable<long>> AddId(IEnumerable<TDboCreate> obj)
112
             {
113
             {
113
                 return res.To<IEnumerable<long>>();
114
                 return res.To<IEnumerable<long>>();
114
             }
115
             }
115
-            return Db.AddId(res.Data);
116
+            return NextCrud.AddId(res.Data);
116
         }
117
         }
117
 
118
 
118
         public LuResult<long> AddId(TDboCreate obj)
119
         public LuResult<long> AddId(TDboCreate obj)
122
             {
123
             {
123
                 return res.To<long>();
124
                 return res.To<long>();
124
             }
125
             }
125
-            return Db.AddId(res.Data);
126
+            return NextCrud.AddId(res.Data);
126
         }
127
         }
127
 
128
 
128
         public LuResult<IEnumerable<TDboRead>> AddDbo(IEnumerable<TDboCreate> obj)
129
         public LuResult<IEnumerable<TDboRead>> AddDbo(IEnumerable<TDboCreate> obj)
132
             {
133
             {
133
                 return res.To<IEnumerable<TDboRead>>();
134
                 return res.To<IEnumerable<TDboRead>>();
134
             }
135
             }
135
-            return Db.AddDbo(res.Data);
136
+            return NextCrud.AddDbo(res.Data);
136
         }
137
         }
137
 
138
 
138
         public LuResult<TDboRead> AddDbo(TDboCreate obj)
139
         public LuResult<TDboRead> AddDbo(TDboCreate obj)
142
             {
143
             {
143
                 return res.To<TDboRead>();
144
                 return res.To<TDboRead>();
144
             }
145
             }
145
-            return Db.AddDbo(res.Data);
146
+            return NextCrud.AddDbo(res.Data);
146
         }
147
         }
147
 
148
 
148
 
149
 
150
 
151
 
151
         public LuResult<TDboRead> GetSingleByKeys(params KeyValuePair<string, object>[] keys)
152
         public LuResult<TDboRead> GetSingleByKeys(params KeyValuePair<string, object>[] keys)
152
         {
153
         {
153
-            return Db.GetSingleByKeys(keys);
154
+            return NextCrud.GetSingleByKeys(keys);
154
         }
155
         }
155
 
156
 
156
         public LuResult<TDboRead> GetSingleById(string id)
157
         public LuResult<TDboRead> GetSingleById(string id)
157
         {
158
         {
158
-            return Db.GetSingleById(id);
159
+            return NextCrud.GetSingleById(id);
159
         }
160
         }
160
 
161
 
161
         public LuResult<TDboRead> GetSingleById(long id)
162
         public LuResult<TDboRead> GetSingleById(long id)
162
         {
163
         {
163
-            return Db.GetSingleById(id);
164
+            return NextCrud.GetSingleById(id);
165
+        }
166
+
167
+        public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, int page = 0, int perPage = int.MaxValue)
168
+        {
169
+            return NextCrud.GetMultiple(orderBy, 0, perPage);
164
         }
170
         }
165
 
171
 
166
 
172
 
173
             {
179
             {
174
                 return obj.To<T>();
180
                 return obj.To<T>();
175
             }
181
             }
176
-            return Db.EditSingleById(id, obj.Data, returnFunc);
182
+            return NextCrud.EditSingleById(id, obj.Data, returnFunc);
177
         }
183
         }
178
 
184
 
179
         public LuResult<long> EditSingleByIdId(long id, TDboUpdate update)
185
         public LuResult<long> EditSingleByIdId(long id, TDboUpdate update)
183
             {
189
             {
184
                 return obj.To<long>();
190
                 return obj.To<long>();
185
             }
191
             }
186
-            return Db.EditSingleByIdId(id, obj.Data);
192
+            return NextCrud.EditSingleByIdId(id, obj.Data);
187
         }
193
         }
188
 
194
 
189
         public LuResult<TDboRead> EditSingleByIdDbo(long id, TDboUpdate update)
195
         public LuResult<TDboRead> EditSingleByIdDbo(long id, TDboUpdate update)
193
             {
199
             {
194
                 return obj.To<TDboRead>();
200
                 return obj.To<TDboRead>();
195
             }
201
             }
196
-            return Db.EditSingleByIdDbo(id, obj.Data);
202
+            return NextCrud.EditSingleByIdDbo(id, obj.Data);
197
         }
203
         }
198
 
204
 
199
         public LuResult<T> EditSingleById<T>(string id, TDboUpdate update, Func<TDboRead, T> returnFunc)
205
         public LuResult<T> EditSingleById<T>(string id, TDboUpdate update, Func<TDboRead, T> returnFunc)
203
             {
209
             {
204
                 return obj.To<T>();
210
                 return obj.To<T>();
205
             }
211
             }
206
-            return Db.EditSingleById(id, obj.Data, returnFunc);
212
+            return NextCrud.EditSingleById(id, obj.Data, returnFunc);
207
         }
213
         }
208
 
214
 
209
         public LuResult<string> EditSingleByIdGuid(string id, TDboUpdate update)
215
         public LuResult<string> EditSingleByIdGuid(string id, TDboUpdate update)
213
             {
219
             {
214
                 return obj.To<string>();
220
                 return obj.To<string>();
215
             }
221
             }
216
-            return Db.EditSingleByIdGuid(id, obj.Data);
222
+            return NextCrud.EditSingleByIdGuid(id, obj.Data);
217
         }
223
         }
218
 
224
 
219
         public LuResult<TDboRead> EditSingleByIdDbo(string id, TDboUpdate update)
225
         public LuResult<TDboRead> EditSingleByIdDbo(string id, TDboUpdate update)
223
             {
229
             {
224
                 return obj.To<TDboRead>();
230
                 return obj.To<TDboRead>();
225
             }
231
             }
226
-            return Db.EditSingleByIdDbo(id, obj.Data);
232
+            return NextCrud.EditSingleByIdDbo(id, obj.Data);
227
         }
233
         }
228
 
234
 
229
 
235
 
231
 
237
 
232
         public LuResult<T> DeleteSingleById<T>(string id, Func<TDboRead, T> returnFunc)
238
         public LuResult<T> DeleteSingleById<T>(string id, Func<TDboRead, T> returnFunc)
233
         {
239
         {
234
-            return Db.DeleteSingleById(id, returnFunc);
240
+            return NextCrud.DeleteSingleById(id, returnFunc);
235
         }
241
         }
236
 
242
 
237
         public LuResult<string> DeleteSingleByIdGuid(string id)
243
         public LuResult<string> DeleteSingleByIdGuid(string id)
238
         {
244
         {
239
-            return Db.DeleteSingleByIdGuid(id);
245
+            return NextCrud.DeleteSingleByIdGuid(id);
240
         }
246
         }
241
 
247
 
242
         public LuResult<TDboRead> DeleteSingleByIdDbo(string id)
248
         public LuResult<TDboRead> DeleteSingleByIdDbo(string id)
243
         {
249
         {
244
-            return Db.DeleteSingleByIdDbo(id);
250
+            return NextCrud.DeleteSingleByIdDbo(id);
245
         }
251
         }
246
 
252
 
247
         public LuResult<T> DeleteSingleById<T>(long id, Func<TDboRead, T> returnFunc)
253
         public LuResult<T> DeleteSingleById<T>(long id, Func<TDboRead, T> returnFunc)
248
         {
254
         {
249
-            return Db.DeleteSingleById(id, returnFunc);
255
+            return NextCrud.DeleteSingleById(id, returnFunc);
250
         }
256
         }
251
 
257
 
252
         public LuResult<long> DeleteSingleByIdId(long id)
258
         public LuResult<long> DeleteSingleByIdId(long id)
253
         {
259
         {
254
-            return Db.DeleteSingleByIdId(id);
260
+            return NextCrud.DeleteSingleByIdId(id);
255
         }
261
         }
256
 
262
 
257
         public LuResult<TDboRead> DeleteSingleByIdDbo(long id)
263
         public LuResult<TDboRead> DeleteSingleByIdDbo(long id)
258
         {
264
         {
259
-            return Db.DeleteSingleByIdDbo(id);
265
+            return NextCrud.DeleteSingleByIdDbo(id);
260
         }
266
         }
261
     }
267
     }
262
 }
268
 }

+ 1
- 3
Luticate2.Utils/Controllers/LuController.cs View File

10
     {
10
     {
11
         protected IConnectionManager ConnectionManager { get; set; }
11
         protected IConnectionManager ConnectionManager { get; set; }
12
 
12
 
13
-        protected IDictionary<object, object> LuItems => (IDictionary<object, object>) HttpContext.Items["luticateItems"];
14
-
15
-//        protected UsersDbo LuCurrentUser => (UsersDbo) LuItems["luticateItems"];
13
+        protected IDictionary<object, object> LuItems => HttpContext.GetLuItems();
16
 
14
 
17
         protected T Handle<T>(LuResult<T> result)
15
         protected T Handle<T>(LuResult<T> result)
18
         {
16
         {

+ 13
- 0
Luticate2.Utils/Controllers/LuUtilsExtensions.cs View File

1
+using System.Collections.Generic;
2
+using Microsoft.AspNetCore.Http;
3
+
4
+namespace Luticate2.Utils.Controllers
5
+{
6
+    public static class LuUtilsExtensions
7
+    {
8
+        public static IDictionary<object, object> GetLuItems(this HttpContext context)
9
+        {
10
+            return (IDictionary<object, object>) context.Items["luticateItems"];
11
+        }
12
+    }
13
+}

Luticate2.Utils/DataAccess/LuEfCrudInterface.cs → Luticate2.Utils/DataAccess/LuEfCrudDataAccess.cs View File

2
 using System.Collections.Generic;
2
 using System.Collections.Generic;
3
 using System.Linq;
3
 using System.Linq;
4
 using System.Linq.Expressions;
4
 using System.Linq.Expressions;
5
+using System.Reflection;
5
 using Luticate2.Utils.Dbo;
6
 using Luticate2.Utils.Dbo;
7
+using Luticate2.Utils.Dbo.OrderBy;
6
 using Luticate2.Utils.Interfaces;
8
 using Luticate2.Utils.Interfaces;
7
 using Microsoft.EntityFrameworkCore;
9
 using Microsoft.EntityFrameworkCore;
8
 
10
 
9
 namespace Luticate2.Utils.DataAccess
11
 namespace Luticate2.Utils.DataAccess
10
 {
12
 {
11
-    public abstract class LuEfCrudInterface<TModel, TDboCreate, TDboRead, TDboUpdate, TDbContext> :
13
+    public abstract class LuEfCrudDataAccess<TModel, TDboCreate, TDboRead, TDboUpdate, TDbContext> :
12
             LuEfDataAccess<TModel, TDbContext>, ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate>
14
             LuEfDataAccess<TModel, TDbContext>, ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate>
13
         where TModel : class
15
         where TModel : class
14
         where TDboCreate : class
16
         where TDboCreate : class
16
         where TDboUpdate : class
18
         where TDboUpdate : class
17
         where TDbContext : DbContext
19
         where TDbContext : DbContext
18
     {
20
     {
19
-        protected LuEfCrudInterface(TDbContext db, DbSet<TModel> table) : base(db, table)
21
+        protected LuEfCrudDataAccess(TDbContext db, DbSet<TModel> table) : base(db, table)
20
         {
22
         {
21
         }
23
         }
22
 
24
 
26
 
28
 
27
         protected abstract TDboRead GetDboFromModel(TModel model);
29
         protected abstract TDboRead GetDboFromModel(TModel model);
28
 
30
 
31
+        protected string GetFieldName(string name)
32
+        {
33
+            return
34
+                string.Concat(name.Select((x, i) => i > 0 && char.IsUpper(x) ? "_" + x.ToString() : x.ToString()))
35
+                    .ToLower();
36
+        }
37
+
29
         protected Func<TDboRead, T> GetIdFunc<T>()
38
         protected Func<TDboRead, T> GetIdFunc<T>()
30
         {
39
         {
31
             var param = Expression.Parameter(typeof(TDboRead), "x");
40
             var param = Expression.Parameter(typeof(TDboRead), "x");
130
         }
139
         }
131
 
140
 
132
 
141
 
133
-        public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(Func<DbSet<TModel>, IQueryable<TModel>> orderBy,
142
+        public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(Func<DbSet<TModel>, IOrderedQueryable<TModel>> orderBy,
134
             Expression<Func<TModel, bool>> predicate, int page = 0, int perPage = int.MaxValue,
143
             Expression<Func<TModel, bool>> predicate, int page = 0, int perPage = int.MaxValue,
135
-            params Func<DbSet<TModel>, IQueryable<TModel>>[] otherOrderBy)
144
+            params Func<IOrderedQueryable<TModel>, IOrderedQueryable<TModel>>[] otherOrderBy)
136
         {
145
         {
137
             return Execute(() =>
146
             return Execute(() =>
138
             {
147
             {
140
                 var ordered = orderBy(Table);
149
                 var ordered = orderBy(Table);
141
                 foreach (var func in otherOrderBy)
150
                 foreach (var func in otherOrderBy)
142
                 {
151
                 {
143
-                    ordered = func(Table);
152
+                    ordered = func(ordered);
144
                 }
153
                 }
145
                 var data = ordered.Where(predicate).Skip(page * perPage).Take(perPage).Select(GetDboFromModel).ToList();
154
                 var data = ordered.Where(predicate).Skip(page * perPage).Take(perPage).Select(GetDboFromModel).ToList();
146
                 var result = new LuPaginatedDbo<TDboRead>
155
                 var result = new LuPaginatedDbo<TDboRead>
157
             params Expression<Func<TModel, object>>[] otherOrderBy)
166
             params Expression<Func<TModel, object>>[] otherOrderBy)
158
         {
167
         {
159
             return GetMultiple(table => table.OrderBy(orderBy), predicate, page, perPage,
168
             return GetMultiple(table => table.OrderBy(orderBy), predicate, page, perPage,
160
-                otherOrderBy.Select<Expression<Func<TModel, object>>, Func<DbSet<TModel>,
161
-                    IQueryable<TModel>>>(expression => (t => t.OrderBy(expression))).ToArray());
169
+                otherOrderBy.Select<Expression<Func<TModel, object>>, Func<IOrderedQueryable<TModel>,
170
+                    IOrderedQueryable<TModel>>>(expression => (t => t.ThenBy(expression))).ToArray());
162
         }
171
         }
163
 
172
 
164
-        public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(Func<DbSet<TModel>, IQueryable<TModel>> orderBy,
165
-            int page = 0, int perPage = int.MaxValue, params Func<DbSet<TModel>, IQueryable<TModel>>[] otherOrderBy)
173
+        public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(Func<DbSet<TModel>, IOrderedQueryable<TModel>> orderBy,
174
+            int page = 0, int perPage = int.MaxValue, params Func<IOrderedQueryable<TModel>, IOrderedQueryable<TModel>>[] otherOrderBy)
166
         {
175
         {
167
             return GetMultiple(orderBy, x => true, page, perPage, otherOrderBy);
176
             return GetMultiple(orderBy, x => true, page, perPage, otherOrderBy);
168
         }
177
         }
170
         public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(Expression<Func<TModel, object>> orderBy,
179
         public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(Expression<Func<TModel, object>> orderBy,
171
             int page = 0, int perPage = int.MaxValue, params Expression<Func<TModel, object>>[] otherOrderBy)
180
             int page = 0, int perPage = int.MaxValue, params Expression<Func<TModel, object>>[] otherOrderBy)
172
         {
181
         {
173
-            return GetMultiple(table => table.OrderBy(orderBy), x => true, page, perPage,
174
-                otherOrderBy.Select<Expression<Func<TModel, object>>, Func<DbSet<TModel>,
175
-                    IQueryable<TModel>>>(expression => (t => t.OrderBy(expression))).ToArray());
182
+            return GetMultiple(orderBy, x => true, page, perPage, otherOrderBy);
176
         }
183
         }
177
 
184
 
185
+        public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, int page = 0, int perPage = int.MaxValue)
186
+        {
187
+            return Execute(() =>
188
+            {
189
+                var count = Table.Count();
190
+                IOrderedQueryable<TModel> ordered = null;
191
+                foreach (var field in orderBy.Fields)
192
+                {
193
+                    var fieldName = GetFieldName(field.Name);
194
+                    var param = Expression.Parameter(typeof(TModel), "x");
195
+                    var prop = Expression.Property(param, fieldName);
196
+                    var converted = Expression.Convert(prop, typeof(object));
197
+                    var exp = Expression.Lambda<Func<TModel, object>>(converted, param);
198
+                    if (ordered != null)
199
+                    {
200
+                        ordered = field.Asc ? ordered.ThenBy(exp) : ordered.ThenByDescending(exp);
201
+                    }
202
+                    else
203
+                    {
204
+                        ordered = field.Asc ? Table.OrderBy(exp) : Table.OrderByDescending(exp);
205
+                    }
206
+                }
207
+
208
+                var data = ordered.Skip(page * perPage).Take(perPage).Select(GetDboFromModel).ToList();
209
+                var result = new LuPaginatedDbo<TDboRead>
210
+                {
211
+                    Count = count,
212
+                    Data = data
213
+                };
214
+                return LuResult<LuPaginatedDbo<TDboRead>>.Ok(result);
215
+            });
216
+        }
178
 
217
 
179
 
218
 
180
 
219
 

+ 4
- 0
Luticate2.Utils/Dbo/OrderBy/LuOrderByBinder.cs View File

8
     {
8
     {
9
         public static LuResult<LuOrderByDbo> FromString(string data)
9
         public static LuResult<LuOrderByDbo> FromString(string data)
10
         {
10
         {
11
+            if (data == null)
12
+            {
13
+                data = "";
14
+            }
11
             data = data.Trim();
15
             data = data.Trim();
12
             var dbo = new LuOrderByDbo {Fields = new List<LuOrderByFieldDbo>()};
16
             var dbo = new LuOrderByDbo {Fields = new List<LuOrderByFieldDbo>()};
13
             if (data != "")
17
             if (data != "")

+ 5
- 0
Luticate2.Utils/Interfaces/ILuCrudInterface.cs View File

1
 using System;
1
 using System;
2
 using System.Collections.Generic;
2
 using System.Collections.Generic;
3
 using Luticate2.Utils.Dbo;
3
 using Luticate2.Utils.Dbo;
4
+using Luticate2.Utils.Dbo.OrderBy;
4
 
5
 
5
 namespace Luticate2.Utils.Interfaces
6
 namespace Luticate2.Utils.Interfaces
6
 {
7
 {
37
         LuResult<TDboRead> GetSingleById(long id);
38
         LuResult<TDboRead> GetSingleById(long id);
38
 
39
 
39
 
40
 
41
+        LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, int page = 0, int perPage = int.MaxValue);
42
+
43
+
44
+
40
 
45
 
41
         LuResult<T> EditSingleById<T>(long id, TDboUpdate update, Func<TDboRead, T> returnFunc);
46
         LuResult<T> EditSingleById<T>(long id, TDboUpdate update, Func<TDboRead, T> returnFunc);
42
 
47
 

+ 1
- 1
Test/Utils/DataAccess/LuUtilsPkBigSerialDataAccess.cs View File

4
 
4
 
5
 namespace Test.Utils.DataAccess
5
 namespace Test.Utils.DataAccess
6
 {
6
 {
7
-    public class LuUtilsPkBigSerialDataAccess : LuEfCrudInterface<pk_bigserial, PkBigSerialAddDbo, PkBigSerialDbo, PkBigSerialAddDbo, LuUtilsDbContext>
7
+    public class LuUtilsPkBigSerialDataAccess : LuEfCrudDataAccess<pk_bigserial, PkBigSerialAddDbo, PkBigSerialDbo, PkBigSerialAddDbo, LuUtilsDbContext>
8
     {
8
     {
9
         public LuUtilsPkBigSerialDataAccess(LuUtilsDbContext db) : base(db, db.pk_bigserial)
9
         public LuUtilsPkBigSerialDataAccess(LuUtilsDbContext db) : base(db, db.pk_bigserial)
10
         {
10
         {

+ 1
- 1
Test/Utils/DataAccess/LuUtilsPkGuidDataAccess.cs View File

4
 
4
 
5
 namespace Test.Utils.DataAccess
5
 namespace Test.Utils.DataAccess
6
 {
6
 {
7
-    public class LuUtilsPkGuidDataAccess : LuEfCrudInterface<pk_guid, PkGuidAddDbo, PkGuidDbo, PkGuidAddDbo, LuUtilsDbContext>
7
+    public class LuUtilsPkGuidDataAccess : LuEfCrudDataAccess<pk_guid, PkGuidAddDbo, PkGuidDbo, PkGuidAddDbo, LuUtilsDbContext>
8
     {
8
     {
9
         public LuUtilsPkGuidDataAccess(LuUtilsDbContext db) : base(db, db.pk_guid)
9
         public LuUtilsPkGuidDataAccess(LuUtilsDbContext db) : base(db, db.pk_guid)
10
         {
10
         {

+ 113
- 18
Test/Utils/EfCrudDataAccess/LuEfReadDataAccessTest.cs View File

2
 using System.Collections.Generic;
2
 using System.Collections.Generic;
3
 using System.Linq;
3
 using System.Linq;
4
 using Luticate2.Utils.Dbo;
4
 using Luticate2.Utils.Dbo;
5
+using Luticate2.Utils.Dbo.OrderBy;
5
 using Test.Utils.DataAccess;
6
 using Test.Utils.DataAccess;
6
 using Test.Utils.Dbo.PkBigSerial;
7
 using Test.Utils.Dbo.PkBigSerial;
7
 using Test.Utils.Dbo.PkGuid;
8
 using Test.Utils.Dbo.PkGuid;
8
 using Xunit;
9
 using Xunit;
9
 
10
 
10
-namespace Test.Utils.EfCrubDataAccess
11
+namespace Test.Utils.EfCrudDataAccess
11
 {
12
 {
12
     public class LuEfReadDataAccessTest
13
     public class LuEfReadDataAccessTest
13
     {
14
     {
195
                     },
196
                     },
196
                     new PkGuidAddDbo
197
                     new PkGuidAddDbo
197
                     {
198
                     {
198
-                        SomeInt = 24,
199
+                        SomeInt = 142,
199
                         SomeText = "24"
200
                         SomeText = "24"
200
                     }
201
                     }
201
                 };
202
                 };
204
                 Assert.Equal(LuStatus.Success, res.Status);
205
                 Assert.Equal(LuStatus.Success, res.Status);
205
 
206
 
206
                 var get = service.GetMultiple(table => table.OrderBy(guid => guid.some_int),
207
                 var get = service.GetMultiple(table => table.OrderBy(guid => guid.some_int),
207
-                    guid => guid.some_int == 42, 0, int.MaxValue, set => set.OrderBy(guid => guid.some_text));
208
-
208
+                    guid => guid.some_int == 42, 0, int.MaxValue, set => set.ThenBy(guid => guid.some_text));
209
                 Assert.Equal(LuStatus.Success, get.Status);
209
                 Assert.Equal(LuStatus.Success, get.Status);
210
                 Assert.Equal(2, get.Data.Count);
210
                 Assert.Equal(2, get.Data.Count);
211
                 Assert.Equal(2, get.Data.Data.Count);
211
                 Assert.Equal(2, get.Data.Data.Count);
239
                     },
239
                     },
240
                     new PkGuidAddDbo
240
                     new PkGuidAddDbo
241
                     {
241
                     {
242
-                        SomeInt = 24,
242
+                        SomeInt = 142,
243
                         SomeText = "24"
243
                         SomeText = "24"
244
                     }
244
                     }
245
                 };
245
                 };
249
 
249
 
250
                 var get = service.GetMultiple(guid => guid.some_int, guid => guid.some_int == 42, 0, int.MaxValue,
250
                 var get = service.GetMultiple(guid => guid.some_int, guid => guid.some_int == 42, 0, int.MaxValue,
251
                     guid => guid.some_text);
251
                     guid => guid.some_text);
252
-
253
                 Assert.Equal(LuStatus.Success, get.Status);
252
                 Assert.Equal(LuStatus.Success, get.Status);
254
                 Assert.Equal(2, get.Data.Count);
253
                 Assert.Equal(2, get.Data.Count);
255
                 Assert.Equal(2, get.Data.Data.Count);
254
                 Assert.Equal(2, get.Data.Data.Count);
283
                     },
282
                     },
284
                     new PkGuidAddDbo
283
                     new PkGuidAddDbo
285
                     {
284
                     {
286
-                        SomeInt = 24,
285
+                        SomeInt = 142,
287
                         SomeText = "24"
286
                         SomeText = "24"
288
                     }
287
                     }
289
                 };
288
                 };
292
                 Assert.Equal(LuStatus.Success, res.Status);
291
                 Assert.Equal(LuStatus.Success, res.Status);
293
 
292
 
294
                 var get = service.GetMultiple(table => table.OrderBy(guid => guid.some_int), 0, int.MaxValue,
293
                 var get = service.GetMultiple(table => table.OrderBy(guid => guid.some_int), 0, int.MaxValue,
295
-                    set => set.OrderBy(guid => guid.some_text));
296
-
294
+                    set => set.ThenBy(guid => guid.some_text));
297
                 Assert.Equal(LuStatus.Success, get.Status);
295
                 Assert.Equal(LuStatus.Success, get.Status);
298
                 Assert.Equal(3, get.Data.Count);
296
                 Assert.Equal(3, get.Data.Count);
299
                 Assert.Equal(3, get.Data.Data.Count);
297
                 Assert.Equal(3, get.Data.Data.Count);
300
 
298
 
301
                 var dbo = get.Data.Data[0];
299
                 var dbo = get.Data.Data[0];
302
-                Assert.Equal(24, dbo.SomeInt);
303
-                Assert.Equal("24", dbo.SomeText);
304
-
305
-                dbo = get.Data.Data[1];
306
                 Assert.Equal(42, dbo.SomeInt);
300
                 Assert.Equal(42, dbo.SomeInt);
307
                 Assert.Equal("42", dbo.SomeText);
301
                 Assert.Equal("42", dbo.SomeText);
308
 
302
 
309
-                dbo = get.Data.Data[2];
303
+                dbo = get.Data.Data[1];
310
                 Assert.Equal(42, dbo.SomeInt);
304
                 Assert.Equal(42, dbo.SomeInt);
311
                 Assert.Equal("442", dbo.SomeText);
305
                 Assert.Equal("442", dbo.SomeText);
306
+
307
+                dbo = get.Data.Data[2];
308
+                Assert.Equal(142, dbo.SomeInt);
309
+                Assert.Equal("24", dbo.SomeText);
312
             });
310
             });
313
         }
311
         }
314
 
312
 
331
                     },
329
                     },
332
                     new PkGuidAddDbo
330
                     new PkGuidAddDbo
333
                     {
331
                     {
334
-                        SomeInt = 24,
332
+                        SomeInt = 142,
335
                         SomeText = "24"
333
                         SomeText = "24"
336
                     }
334
                     }
337
                 };
335
                 };
340
                 Assert.Equal(LuStatus.Success, res.Status);
338
                 Assert.Equal(LuStatus.Success, res.Status);
341
 
339
 
342
                 var get = service.GetMultiple(guid => guid.some_int, 0, int.MaxValue, guid => guid.some_text);
340
                 var get = service.GetMultiple(guid => guid.some_int, 0, int.MaxValue, guid => guid.some_text);
343
-
344
                 Assert.Equal(LuStatus.Success, get.Status);
341
                 Assert.Equal(LuStatus.Success, get.Status);
345
                 Assert.Equal(3, get.Data.Count);
342
                 Assert.Equal(3, get.Data.Count);
346
                 Assert.Equal(3, get.Data.Data.Count);
343
                 Assert.Equal(3, get.Data.Data.Count);
347
 
344
 
348
                 var dbo = get.Data.Data[0];
345
                 var dbo = get.Data.Data[0];
349
-                Assert.Equal(24, dbo.SomeInt);
350
-                Assert.Equal("24", dbo.SomeText);
346
+                Assert.Equal(42, dbo.SomeInt);
347
+                Assert.Equal("42", dbo.SomeText);
351
 
348
 
352
                 dbo = get.Data.Data[1];
349
                 dbo = get.Data.Data[1];
353
                 Assert.Equal(42, dbo.SomeInt);
350
                 Assert.Equal(42, dbo.SomeInt);
351
+                Assert.Equal("442", dbo.SomeText);
352
+
353
+                dbo = get.Data.Data[2];
354
+                Assert.Equal(142, dbo.SomeInt);
355
+                Assert.Equal("24", dbo.SomeText);
356
+            });
357
+        }
358
+
359
+        [Fact]
360
+        public void TestGetMultiple5()
361
+        {
362
+            Tests.TestRealDb(context =>
363
+            {
364
+                var dbos = new List<PkGuidAddDbo>
365
+                {
366
+                    new PkGuidAddDbo
367
+                    {
368
+                        SomeInt = 42,
369
+                        SomeText = "442"
370
+                    },
371
+                    new PkGuidAddDbo
372
+                    {
373
+                        SomeInt = 42,
374
+                        SomeText = "42"
375
+                    },
376
+                    new PkGuidAddDbo
377
+                    {
378
+                        SomeInt = 142,
379
+                        SomeText = "24"
380
+                    }
381
+                };
382
+                var service = new LuUtilsPkGuidDataAccess(context);
383
+                var res = service.AddGuid(dbos);
384
+                Assert.Equal(LuStatus.Success, res.Status);
385
+
386
+                var orderBy = LuOrderByBinder.FromString("someInt,someText");
387
+                Assert.Equal(LuStatus.Success, orderBy.Status);
388
+
389
+                var get = service.GetMultiple(orderBy.Data);
390
+                Assert.Equal(LuStatus.Success, get.Status);
391
+                Assert.Equal(3, get.Data.Count);
392
+                Assert.Equal(3, get.Data.Data.Count);
393
+
394
+                var dbo = get.Data.Data[0];
395
+                Assert.Equal(42, dbo.SomeInt);
354
                 Assert.Equal("42", dbo.SomeText);
396
                 Assert.Equal("42", dbo.SomeText);
355
 
397
 
398
+                dbo = get.Data.Data[1];
399
+                Assert.Equal(42, dbo.SomeInt);
400
+                Assert.Equal("442", dbo.SomeText);
401
+
356
                 dbo = get.Data.Data[2];
402
                 dbo = get.Data.Data[2];
403
+                Assert.Equal(142, dbo.SomeInt);
404
+                Assert.Equal("24", dbo.SomeText);
405
+            });
406
+        }
407
+
408
+        [Fact]
409
+        public void TestGetMultiple6()
410
+        {
411
+            Tests.TestRealDb(context =>
412
+            {
413
+                var dbos = new List<PkGuidAddDbo>
414
+                {
415
+                    new PkGuidAddDbo
416
+                    {
417
+                        SomeInt = 42,
418
+                        SomeText = "442"
419
+                    },
420
+                    new PkGuidAddDbo
421
+                    {
422
+                        SomeInt = 42,
423
+                        SomeText = "42"
424
+                    },
425
+                    new PkGuidAddDbo
426
+                    {
427
+                        SomeInt = 142,
428
+                        SomeText = "24"
429
+                    }
430
+                };
431
+                var service = new LuUtilsPkGuidDataAccess(context);
432
+                var res = service.AddGuid(dbos);
433
+                Assert.Equal(LuStatus.Success, res.Status);
434
+
435
+                var orderBy = LuOrderByBinder.FromString("someText:desc,someInt");
436
+                Assert.Equal(LuStatus.Success, orderBy.Status);
437
+
438
+                var get = service.GetMultiple(orderBy.Data);
439
+                Assert.Equal(LuStatus.Success, get.Status);
440
+                Assert.Equal(3, get.Data.Count);
441
+                Assert.Equal(3, get.Data.Data.Count);
442
+
443
+                var dbo = get.Data.Data[0];
357
                 Assert.Equal(42, dbo.SomeInt);
444
                 Assert.Equal(42, dbo.SomeInt);
358
                 Assert.Equal("442", dbo.SomeText);
445
                 Assert.Equal("442", dbo.SomeText);
446
+
447
+                dbo = get.Data.Data[1];
448
+                Assert.Equal(42, dbo.SomeInt);
449
+                Assert.Equal("42", dbo.SomeText);
450
+
451
+                dbo = get.Data.Data[2];
452
+                Assert.Equal(142, dbo.SomeInt);
453
+                Assert.Equal("24", dbo.SomeText);
359
             });
454
             });
360
         }
455
         }
361
     }
456
     }

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

6
 {
6
 {
7
     public class PkGuidBusiness : LuCrudBusiness<LuUtilsPkGuidDataAccess, PkGuidAddDbo, PkGuidDbo, PkGuidAddDbo>
7
     public class PkGuidBusiness : LuCrudBusiness<LuUtilsPkGuidDataAccess, PkGuidAddDbo, PkGuidDbo, PkGuidAddDbo>
8
     {
8
     {
9
-        public PkGuidBusiness(LuUtilsPkGuidDataAccess db) : base(db)
9
+        public PkGuidBusiness(LuUtilsPkGuidDataAccess nextCrud) : base(nextCrud)
10
         {
10
         {
11
         }
11
         }
12
     }
12
     }

+ 5
- 4
WebTest/Controllers/PkGuidController.cs View File

1
-using Luticate2.Utils.Controllers;
1
+using System.Collections.Generic;
2
+using Luticate2.Utils.Controllers;
3
+using Luticate2.Utils.Dbo;
2
 using Luticate2.Utils.Dbo.OrderBy;
4
 using Luticate2.Utils.Dbo.OrderBy;
3
 using Microsoft.AspNetCore.Mvc;
5
 using Microsoft.AspNetCore.Mvc;
4
 using Test.Utils.Dbo.PkGuid;
6
 using Test.Utils.Dbo.PkGuid;
22
         }
24
         }
23
 
25
 
24
         [Route("[controller]")]
26
         [Route("[controller]")]
25
-        public PkGuidDbo Get(LuOrderByDbo orderBy)
27
+        public LuPaginatedDbo<PkGuidDbo> Get(LuOrderByDbo orderBy, int page = 0, int perPage = int.MaxValue)
26
         {
28
         {
27
-            return new PkGuidDbo();
28
-//            return Handle(_busines.GetMultiple());
29
+            return Handle(_busines.GetMultiple(orderBy, page, perPage));
29
         }
30
         }
30
     }
31
     }
31
 }
32
 }

Loading…
Cancel
Save