Browse Source

generifyed long/string id; begin websockets

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

+ 27
- 105
Luticate2.Utils/Business/LuCrudBusiness.cs View File

8
 
8
 
9
 namespace Luticate2.Utils.Business
9
 namespace Luticate2.Utils.Business
10
 {
10
 {
11
-    public abstract class LuCrudBusiness<TDataAccess, TDboCreate, TDboRead, TDboUpdate> : LuBusiness, ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate>
12
-        where TDataAccess : ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate>
11
+    public abstract class LuCrudBusiness<TDataAccess, TDboCreate, TDboRead, TDboUpdate, TId> :
12
+            LuBusiness,
13
+            ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate, TId>
14
+        where TDataAccess : ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate, TId>
13
         where TDboCreate : class
15
         where TDboCreate : class
14
         where TDboRead : class
16
         where TDboRead : class
15
         where TDboUpdate : class
17
         where TDboUpdate : class
46
             return LuResult<TDboUpdate>.Ok(update);
48
             return LuResult<TDboUpdate>.Ok(update);
47
         }
49
         }
48
 
50
 
49
-        protected LuResult<TDboUpdate> GetAndCheckEdit(string id, TDboUpdate update)
51
+        protected LuResult<TDboUpdate> GetAndCheckEdit(TId id, TDboUpdate update)
50
         {
52
         {
51
             var res = GetSingleById(id);
53
             var res = GetSingleById(id);
52
             if (!res)
54
             if (!res)
56
             return CheckEdit(res.Data, update);
58
             return CheckEdit(res.Data, update);
57
         }
59
         }
58
 
60
 
59
-        protected LuResult<TDboUpdate> GetAndCheckEdit(long id, TDboUpdate update)
60
-        {
61
-            var res = GetSingleById(id);
62
-            if (!res)
63
-            {
64
-                return res.To<TDboUpdate>();
65
-            }
66
-            return CheckEdit(res.Data, update);
67
-        }
68
 
61
 
69
 
62
 
70
 
63
 
71
-
72
-        public LuResult<T> Add<T>(IEnumerable<TDboCreate> objs, Func<IEnumerable<TDboRead>, T> returnFunc)
64
+        public virtual LuResult<T> Add<T>(IEnumerable<TDboCreate> objs, Func<IEnumerable<TDboRead>, T> returnFunc)
73
         {
65
         {
74
             var res = CheckAdd(objs);
66
             var res = CheckAdd(objs);
75
             if (!res)
67
             if (!res)
79
             return DataAccess.Add(res.Data, returnFunc);
71
             return DataAccess.Add(res.Data, returnFunc);
80
         }
72
         }
81
 
73
 
82
-        public LuResult<T> Add<T>(TDboCreate obj, Func<TDboRead, T> returnFunc)
74
+        public virtual LuResult<T> Add<T>(TDboCreate obj, Func<TDboRead, T> returnFunc)
83
         {
75
         {
84
             var res = CheckAdd(obj);
76
             var res = CheckAdd(obj);
85
             if (!res)
77
             if (!res)
89
             return DataAccess.Add(res.Data, returnFunc);
81
             return DataAccess.Add(res.Data, returnFunc);
90
         }
82
         }
91
 
83
 
92
-        public LuResult<IEnumerable<string>> AddGuid(IEnumerable<TDboCreate> objs)
84
+        public virtual LuResult<IEnumerable<TId>> AddId(IEnumerable<TDboCreate> objs)
93
         {
85
         {
94
             var res = CheckAdd(objs);
86
             var res = CheckAdd(objs);
95
             if (!res)
87
             if (!res)
96
             {
88
             {
97
-                return res.To<IEnumerable<string>>();
98
-            }
99
-            return DataAccess.AddGuid(res.Data);
100
-        }
101
-
102
-        public LuResult<string> AddGuid(TDboCreate obj)
103
-        {
104
-            var res = CheckAdd(obj);
105
-            if (!res)
106
-            {
107
-                return res.To<string>();
108
-            }
109
-            return DataAccess.AddGuid(res.Data);
110
-        }
111
-
112
-        public LuResult<IEnumerable<long>> AddId(IEnumerable<TDboCreate> obj)
113
-        {
114
-            var res = CheckAdd(obj);
115
-            if (!res)
116
-            {
117
-                return res.To<IEnumerable<long>>();
89
+                return res.To<IEnumerable<TId>>();
118
             }
90
             }
119
             return DataAccess.AddId(res.Data);
91
             return DataAccess.AddId(res.Data);
120
         }
92
         }
121
 
93
 
122
-        public LuResult<long> AddId(TDboCreate obj)
94
+        public virtual LuResult<TId> AddId(TDboCreate obj)
123
         {
95
         {
124
             var res = CheckAdd(obj);
96
             var res = CheckAdd(obj);
125
             if (!res)
97
             if (!res)
126
             {
98
             {
127
-                return res.To<long>();
99
+                return res.To<TId>();
128
             }
100
             }
129
             return DataAccess.AddId(res.Data);
101
             return DataAccess.AddId(res.Data);
130
         }
102
         }
131
 
103
 
132
-        public LuResult<IEnumerable<TDboRead>> AddDbo(IEnumerable<TDboCreate> obj)
104
+        public virtual LuResult<IEnumerable<TDboRead>> AddDbo(IEnumerable<TDboCreate> obj)
133
         {
105
         {
134
             var res = CheckAdd(obj);
106
             var res = CheckAdd(obj);
135
             if (!res)
107
             if (!res)
139
             return DataAccess.AddDbo(res.Data);
111
             return DataAccess.AddDbo(res.Data);
140
         }
112
         }
141
 
113
 
142
-        public LuResult<TDboRead> AddDbo(TDboCreate obj)
114
+        public virtual LuResult<TDboRead> AddDbo(TDboCreate obj)
143
         {
115
         {
144
             var res = CheckAdd(obj);
116
             var res = CheckAdd(obj);
145
             if (!res)
117
             if (!res)
152
 
124
 
153
 
125
 
154
 
126
 
155
-        public LuResult<TDboRead> GetSingleById(string id)
127
+        public virtual LuResult<TDboRead> GetSingleById(TId id)
156
         {
128
         {
157
             return DataAccess.GetSingleById(id);
129
             return DataAccess.GetSingleById(id);
158
         }
130
         }
159
 
131
 
160
-        public LuResult<TDboRead> GetSingleById(long id)
161
-        {
162
-            return DataAccess.GetSingleById(id);
163
-        }
164
 
132
 
165
-
166
-        public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, LuFilterDbo filter,
133
+        public virtual LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, LuFilterDbo filter,
167
             int page = 0, int perPage = int.MaxValue)
134
             int page = 0, int perPage = int.MaxValue)
168
         {
135
         {
169
             return DataAccess.GetMultiple(orderBy, filter, page, perPage);
136
             return DataAccess.GetMultiple(orderBy, filter, page, perPage);
170
         }
137
         }
171
 
138
 
172
-        public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, int page = 0,
139
+        public virtual LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, int page = 0,
173
             int perPage = int.MaxValue)
140
             int perPage = int.MaxValue)
174
         {
141
         {
175
             return DataAccess.GetMultiple(orderBy, page, perPage);
142
             return DataAccess.GetMultiple(orderBy, page, perPage);
178
 
145
 
179
 
146
 
180
 
147
 
181
-        public LuResult<T> EditSingleById<T>(long id, TDboUpdate update, Func<TDboRead, T> returnFunc)
148
+        public virtual LuResult<T> EditSingleById<T>(TId id, TDboUpdate update, Func<TDboRead, T> returnFunc)
182
         {
149
         {
183
             var obj = GetAndCheckEdit(id, update);
150
             var obj = GetAndCheckEdit(id, update);
184
             if (!obj)
151
             if (!obj)
188
             return DataAccess.EditSingleById(id, obj.Data, returnFunc);
155
             return DataAccess.EditSingleById(id, obj.Data, returnFunc);
189
         }
156
         }
190
 
157
 
191
-        public LuResult<long> EditSingleByIdId(long id, TDboUpdate update)
158
+        public virtual LuResult<TId> EditSingleByIdId(TId id, TDboUpdate update)
192
         {
159
         {
193
             var obj = GetAndCheckEdit(id, update);
160
             var obj = GetAndCheckEdit(id, update);
194
             if (!obj)
161
             if (!obj)
195
             {
162
             {
196
-                return obj.To<long>();
163
+                return obj.To<TId>();
197
             }
164
             }
198
-            return DataAccess.EditSingleByIdId(id, obj.Data);
165
+            return EditSingleById(id, obj.Data, read => (TId)((dynamic)read).Id);
199
         }
166
         }
200
 
167
 
201
-        public LuResult<TDboRead> EditSingleByIdDbo(long id, TDboUpdate update)
168
+        public virtual LuResult<TDboRead> EditSingleByIdDbo(TId id, TDboUpdate update)
202
         {
169
         {
203
             var obj = GetAndCheckEdit(id, update);
170
             var obj = GetAndCheckEdit(id, update);
204
             if (!obj)
171
             if (!obj)
205
             {
172
             {
206
                 return obj.To<TDboRead>();
173
                 return obj.To<TDboRead>();
207
             }
174
             }
208
-            return DataAccess.EditSingleByIdDbo(id, obj.Data);
175
+            return EditSingleById(id, obj.Data, read => read);
209
         }
176
         }
210
 
177
 
211
-        public LuResult<T> EditSingleById<T>(string id, TDboUpdate update, Func<TDboRead, T> returnFunc)
212
-        {
213
-            var obj = GetAndCheckEdit(id, update);
214
-            if (!obj)
215
-            {
216
-                return obj.To<T>();
217
-            }
218
-            return DataAccess.EditSingleById(id, obj.Data, returnFunc);
219
-        }
220
-
221
-        public LuResult<string> EditSingleByIdGuid(string id, TDboUpdate update)
222
-        {
223
-            var obj = GetAndCheckEdit(id, update);
224
-            if (!obj)
225
-            {
226
-                return obj.To<string>();
227
-            }
228
-            return DataAccess.EditSingleByIdGuid(id, obj.Data);
229
-        }
230
-
231
-        public LuResult<TDboRead> EditSingleByIdDbo(string id, TDboUpdate update)
232
-        {
233
-            var obj = GetAndCheckEdit(id, update);
234
-            if (!obj)
235
-            {
236
-                return obj.To<TDboRead>();
237
-            }
238
-            return DataAccess.EditSingleByIdDbo(id, obj.Data);
239
-        }
240
 
178
 
241
 
179
 
242
 
180
 
243
-
244
-        public LuResult<T> DeleteSingleById<T>(string id, Func<TDboRead, T> returnFunc)
245
-        {
246
-            return DataAccess.DeleteSingleById(id, returnFunc);
247
-        }
248
-
249
-        public LuResult<string> DeleteSingleByIdGuid(string id)
250
-        {
251
-            return DataAccess.DeleteSingleByIdGuid(id);
252
-        }
253
-
254
-        public LuResult<TDboRead> DeleteSingleByIdDbo(string id)
255
-        {
256
-            return DataAccess.DeleteSingleByIdDbo(id);
257
-        }
258
-
259
-        public LuResult<T> DeleteSingleById<T>(long id, Func<TDboRead, T> returnFunc)
181
+        public virtual LuResult<T> DeleteSingleById<T>(TId id, Func<TDboRead, T> returnFunc)
260
         {
182
         {
261
             return DataAccess.DeleteSingleById(id, returnFunc);
183
             return DataAccess.DeleteSingleById(id, returnFunc);
262
         }
184
         }
263
 
185
 
264
-        public LuResult<long> DeleteSingleByIdId(long id)
186
+        public virtual LuResult<TId> DeleteSingleByIdId(TId id)
265
         {
187
         {
266
-            return DataAccess.DeleteSingleByIdId(id);
188
+            return DeleteSingleById(id, read => (TId)((dynamic)read).Id);
267
         }
189
         }
268
 
190
 
269
-        public LuResult<TDboRead> DeleteSingleByIdDbo(long id)
191
+        public virtual LuResult<TDboRead> DeleteSingleByIdDbo(TId id)
270
         {
192
         {
271
-            return DataAccess.DeleteSingleByIdDbo(id);
193
+            return DeleteSingleById(id, read => read);
272
         }
194
         }
273
     }
195
     }
274
 }
196
 }

+ 26
- 0
Luticate2.Utils/Business/NotificationsBusiness.cs View File

1
+using Luticate2.Utils.Hubs;
2
+using Microsoft.AspNetCore.SignalR;
3
+using Microsoft.AspNetCore.SignalR.Infrastructure;
4
+
5
+namespace Luticate2.Utils.Business
6
+{
7
+    public class LuNotificationsBusiness
8
+    {
9
+        private readonly IHubContext _hubContext;
10
+
11
+        public LuNotificationsBusiness(IConnectionManager connectionManager)
12
+        {
13
+            _hubContext = connectionManager.GetHubContext<LuNotificationsHub>();
14
+        }
15
+
16
+        public void Notify(string eventName, string entityType, object entity)
17
+        {
18
+            _hubContext.Clients.All.notify(eventName, entityType, entity);
19
+        }
20
+
21
+        public void NotifyUpdate(string eventName, string entityType, object entity)
22
+        {
23
+            Notify("update", entityType, entity);
24
+        }
25
+    }
26
+}

+ 5
- 5
Luticate2.Utils/Controllers/LuCrudController.cs View File

9
 
9
 
10
 namespace Luticate2.Utils.Controllers
10
 namespace Luticate2.Utils.Controllers
11
 {
11
 {
12
-    public abstract class LuCrudController<TBusiness, TDboCreate, TDboRead, TDboUpdate> : LuController
12
+    public abstract class LuCrudController<TBusiness, TDboCreate, TDboRead, TDboUpdate, TId> : LuController
13
         where TDboCreate : class
13
         where TDboCreate : class
14
         where TDboRead : class
14
         where TDboRead : class
15
         where TDboUpdate : class
15
         where TDboUpdate : class
16
-        where TBusiness : ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate>
16
+        where TBusiness : ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate, TId>
17
     {
17
     {
18
         protected readonly TBusiness Busines;
18
         protected readonly TBusiness Busines;
19
 
19
 
24
 
24
 
25
         [HttpGet]
25
         [HttpGet]
26
         [Route("[controller]/{id}")]
26
         [Route("[controller]/{id}")]
27
-        public LuApiWrapperDbo<TDboRead> GetSingleById(string id)
27
+        public LuApiWrapperDbo<TDboRead> GetSingleById(TId id)
28
         {
28
         {
29
             return Handle(Busines.GetSingleById(id));
29
             return Handle(Busines.GetSingleById(id));
30
         }
30
         }
46
 
46
 
47
         [HttpPost]
47
         [HttpPost]
48
         [Route("[controller]/{id}")]
48
         [Route("[controller]/{id}")]
49
-        public LuApiWrapperDbo<TDboRead> EditSingleByIdDbo(string id, [FromBody]TDboUpdate data)
49
+        public LuApiWrapperDbo<TDboRead> EditSingleByIdDbo(TId id, [FromBody]TDboUpdate data)
50
         {
50
         {
51
             return Handle(Busines.EditSingleByIdDbo(id, data));
51
             return Handle(Busines.EditSingleByIdDbo(id, data));
52
         }
52
         }
53
 
53
 
54
         [HttpDelete]
54
         [HttpDelete]
55
         [Route("[controller]/{id}")]
55
         [Route("[controller]/{id}")]
56
-        public LuApiWrapperDbo<TDboRead> Delete(string id)
56
+        public LuApiWrapperDbo<TDboRead> Delete(TId id)
57
         {
57
         {
58
             return Handle(Busines.DeleteSingleByIdDbo(id));
58
             return Handle(Busines.DeleteSingleByIdDbo(id));
59
         }
59
         }

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

1
 using System.Collections.Generic;
1
 using System.Collections.Generic;
2
+using Luticate2.Utils.Business;
2
 using Luticate2.Utils.DataAccess.Npgsql;
3
 using Luticate2.Utils.DataAccess.Npgsql;
3
 using Luticate2.Utils.Dbo.Basic;
4
 using Luticate2.Utils.Dbo.Basic;
4
 using Luticate2.Utils.Dbo.Filter;
5
 using Luticate2.Utils.Dbo.Filter;
22
 
23
 
23
         public static IServiceCollection AddLuticateUtils(this IServiceCollection services, LuOptionsDelegate optionsDelegate)
24
         public static IServiceCollection AddLuticateUtils(this IServiceCollection services, LuOptionsDelegate optionsDelegate)
24
         {
25
         {
26
+            services.AddSingleton<LuNotificationsBusiness>();
25
             Options = new LuOptionsDbo();
27
             Options = new LuOptionsDbo();
26
             optionsDelegate(Options);
28
             optionsDelegate(Options);
29
+            services.AddSignalR(options =>
30
+            {
31
+                options.Hubs.EnableDetailedErrors = true;
32
+            });
27
             return services;
33
             return services;
28
         }
34
         }
29
 
35
 
48
         public static IApplicationBuilder UseLuticateUtils(this IApplicationBuilder app)
54
         public static IApplicationBuilder UseLuticateUtils(this IApplicationBuilder app)
49
         {
55
         {
50
             app.UseMiddleware<LuExceptionMiddleware>();
56
             app.UseMiddleware<LuExceptionMiddleware>();
57
+
58
+            app.UseWebSockets();
59
+            app.UseSignalR();
60
+
51
             return app;
61
             return app;
52
         }
62
         }
53
 
63
 

+ 47
- 121
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 Luticate2.Utils.DataAccess.Npgsql;
6
 using Luticate2.Utils.Dbo.Basic;
5
 using Luticate2.Utils.Dbo.Basic;
7
 using Luticate2.Utils.Dbo.Filter;
6
 using Luticate2.Utils.Dbo.Filter;
8
 using Luticate2.Utils.Dbo.OrderBy;
7
 using Luticate2.Utils.Dbo.OrderBy;
10
 using Luticate2.Utils.Interfaces;
9
 using Luticate2.Utils.Interfaces;
11
 using Luticate2.Utils.Utils;
10
 using Luticate2.Utils.Utils;
12
 using Microsoft.EntityFrameworkCore;
11
 using Microsoft.EntityFrameworkCore;
12
+using Microsoft.EntityFrameworkCore.Metadata.Internal;
13
 
13
 
14
 namespace Luticate2.Utils.DataAccess
14
 namespace Luticate2.Utils.DataAccess
15
 {
15
 {
16
-    public abstract class LuEfCrudDataAccess<TModel, TDboCreate, TDboRead, TDboUpdate, TDbContext> :
17
-            LuEfDataAccess<TModel, TDbContext>, ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate>
16
+    public abstract class LuEfCrudDataAccess<TModel, TDboCreate, TDboRead, TDboUpdate, TDbContext, TId> :
17
+            LuEfDataAccess<TModel, TDbContext>,
18
+            ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate, TId>
18
         where TModel : class
19
         where TModel : class
19
         where TDboCreate : class
20
         where TDboCreate : class
20
         where TDboRead : class
21
         where TDboRead : class
61
             return model;
62
             return model;
62
         }
63
         }
63
 
64
 
64
-        protected Guid? GetGuid(string id)
65
+        protected virtual object GetId(TId id)
65
         {
66
         {
66
-            Guid guid;
67
-            if (Guid.TryParse(id, out guid))
67
+            var s = id as string;
68
+            if (s != null)
68
             {
69
             {
69
-                return guid;
70
+                Guid guid;
71
+                if (Guid.TryParse(s, out guid))
72
+                {
73
+                    return guid;
74
+                }
75
+                return null;
76
+
70
             }
77
             }
71
-            return null;
78
+            return id;
72
         }
79
         }
73
 
80
 
74
         protected LuResult<T> GetNotFoundResult<T>()
81
         protected LuResult<T> GetNotFoundResult<T>()
103
         }
110
         }
104
 
111
 
105
 
112
 
106
-        public LuResult<IEnumerable<string>> AddGuid(IEnumerable<TDboCreate> objs)
113
+        public LuResult<IEnumerable<TId>> AddId(IEnumerable<TDboCreate> objs)
107
         {
114
         {
108
-            var func = GetIdFunc<string>();
115
+            var func = GetIdFunc<TId>();
109
             return Add(objs, list => list.Select(func));
116
             return Add(objs, list => list.Select(func));
110
         }
117
         }
111
 
118
 
112
-        public LuResult<string> AddGuid(TDboCreate obj)
113
-        {
114
-            return AddGuid(new List<TDboCreate> {obj}).To(list => list.First());
115
-        }
116
-
117
-
118
-        public LuResult<IEnumerable<long>> AddId(IEnumerable<TDboCreate> obj)
119
-        {
120
-            var func = GetIdFunc<long>();
121
-            return Add(obj, list => list.Select(func));
122
-        }
123
-
124
-        public LuResult<long> AddId(TDboCreate obj)
119
+        public LuResult<TId> AddId(TDboCreate obj)
125
         {
120
         {
126
             return AddId(new List<TDboCreate> {obj}).To(list => list.First());
121
             return AddId(new List<TDboCreate> {obj}).To(list => list.First());
127
         }
122
         }
159
             return GetSingle(GetExpression(keys));
154
             return GetSingle(GetExpression(keys));
160
         }
155
         }
161
 
156
 
162
-        public LuResult<TDboRead> GetSingleById(string id)
157
+        public LuResult<TDboRead> GetSingleById(TId id)
163
         {
158
         {
164
-            var guid = GetGuid(id);
159
+            var guid = GetId(id);
165
             if (guid == null)
160
             if (guid == null)
166
             {
161
             {
167
                 return GetNotFoundResult<TDboRead>();
162
                 return GetNotFoundResult<TDboRead>();
169
             return GetSingleByKeys(new KeyValuePair<string, object>("id", guid));
164
             return GetSingleByKeys(new KeyValuePair<string, object>("id", guid));
170
         }
165
         }
171
 
166
 
172
-        public LuResult<TDboRead> GetSingleById(long id)
173
-        {
174
-            return GetSingleByKeys(new KeyValuePair<string, object>("id", id));
175
-        }
176
-
177
 
167
 
178
         public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(Func<DbSet<TModel>, IOrderedQueryable<TModel>> orderBy,
168
         public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(Func<DbSet<TModel>, IOrderedQueryable<TModel>> orderBy,
179
             Expression<Func<TModel, bool>> predicate, int page = 0, int perPage = int.MaxValue,
169
             Expression<Func<TModel, bool>> predicate, int page = 0, int perPage = int.MaxValue,
218
             return GetMultiple(orderBy, x => true, page, perPage, otherOrderBy);
208
             return GetMultiple(orderBy, x => true, page, perPage, otherOrderBy);
219
         }
209
         }
220
 
210
 
221
-        public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, LuFilterDbo filter,
211
+        public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, IQueryable<TModel> queryable,
222
             int page = 0, int perPage = int.MaxValue)
212
             int page = 0, int perPage = int.MaxValue)
223
         {
213
         {
224
             return Execute(() =>
214
             return Execute(() =>
225
             {
215
             {
226
-                var queryable = GetFilterQuery(filter);
227
                 var count = queryable.Count();
216
                 var count = queryable.Count();
228
                 IOrderedQueryable<TModel> ordered = null;
217
                 IOrderedQueryable<TModel> ordered = null;
229
                 foreach (var field in orderBy.Fields)
218
                 foreach (var field in orderBy.Fields)
254
             });
243
             });
255
         }
244
         }
256
 
245
 
246
+        public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, LuFilterDbo filter,
247
+            int page = 0, int perPage = int.MaxValue)
248
+        {
249
+            return GetMultiple(orderBy, GetFilterQuery(filter), page, perPage);
250
+        }
251
+
257
         public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, int page = 0, int perPage = int.MaxValue)
252
         public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, int page = 0, int perPage = int.MaxValue)
258
         {
253
         {
259
-            var filter = new LuFilterDbo
260
-            {
261
-                Query = ""
262
-            };
263
-            return GetMultiple(orderBy, filter, page, perPage);
254
+            return GetMultiple(orderBy, Table, page, perPage);
264
         }
255
         }
265
 
256
 
266
 
257
 
284
             });
275
             });
285
         }
276
         }
286
 
277
 
287
-        public LuResult<IEnumerable<string>> EditGuid(Expression<Func<TModel, bool>> predicate, Action<TModel> update)
288
-        {
289
-            var func = GetIdFunc<string>();
290
-            return Edit(predicate, update, reads => reads.Select(func));
291
-        }
292
-
293
-        public LuResult<IEnumerable<long>> EditId(Expression<Func<TModel, bool>> predicate, Action<TModel> update)
278
+        public LuResult<IEnumerable<TId>> EditId(Expression<Func<TModel, bool>> predicate, Action<TModel> update)
294
         {
279
         {
295
-            var func = GetIdFunc<long>();
280
+            var func = GetIdFunc<TId>();
296
             return Edit(predicate, update, reads => reads.Select(func));
281
             return Edit(predicate, update, reads => reads.Select(func));
297
         }
282
         }
298
 
283
 
302
         }
287
         }
303
 
288
 
304
 
289
 
305
-        public LuResult<T> EditSingleById<T>(long id, Action<TModel> update, Func<TDboRead, T> returnFunc)
290
+        public LuResult<T> EditSingleById<T>(TId id, Action<TModel> update, Func<TDboRead, T> returnFunc)
306
         {
291
         {
307
-            return Edit(GetExpression(new KeyValuePair<string, object>("id", id)), update,
308
-                list => returnFunc(list.FirstOrDefault()));
309
-        }
310
-
311
-        public LuResult<long> EditSingleByIdId(long id, Action<TModel> update)
312
-        {
313
-            var func = GetIdFunc<long>();
314
-            return EditSingleById(id, update, func);
315
-        }
316
-
317
-        public LuResult<TDboRead> EditSingleByIdDbo(long id, Action<TModel> update)
318
-        {
319
-            return EditSingleById(id, update, read => read);
320
-        }
321
-
322
-
323
-        public LuResult<T> EditSingleById<T>(string id, Action<TModel> update, Func<TDboRead, T> returnFunc)
324
-        {
325
-            var guid = GetGuid(id);
292
+            var guid = GetId(id);
326
             if (guid == null)
293
             if (guid == null)
327
             {
294
             {
328
                 return GetNotFoundResult<T>();
295
                 return GetNotFoundResult<T>();
331
                 list => returnFunc(list.FirstOrDefault()));
298
                 list => returnFunc(list.FirstOrDefault()));
332
         }
299
         }
333
 
300
 
334
-        public LuResult<string> EditSingleByIdGuid(string id, Action<TModel> update)
335
-        {
336
-            return EditSingleById(id, update, GetIdFunc<string>());
337
-        }
338
-
339
-        public LuResult<TDboRead> EditSingleByIdDbo(string id, Action<TModel> update)
340
-        {
341
-            return EditSingleById(id, update, read => read);
342
-        }
343
-
344
-
345
-        public LuResult<T> EditSingleById<T>(long id, TDboUpdate update, Func<TDboRead, T> returnFunc)
346
-        {
347
-            return Edit(GetExpression(new KeyValuePair<string, object>("id", id)),
348
-                model => EditModelFromTUpdate(update, model), list => returnFunc(list.FirstOrDefault()));
349
-        }
350
-
351
-        public LuResult<long> EditSingleByIdId(long id, TDboUpdate update)
301
+        public LuResult<TId> EditSingleByIdId(TId id, Action<TModel> update)
352
         {
302
         {
353
-            return EditSingleById(id, update, GetIdFunc<long>());
303
+            return EditSingleById(id, update, GetIdFunc<TId>());
354
         }
304
         }
355
 
305
 
356
-        public LuResult<TDboRead> EditSingleByIdDbo(long id, TDboUpdate update)
306
+        public LuResult<TDboRead> EditSingleByIdDbo(TId id, Action<TModel> update)
357
         {
307
         {
358
             return EditSingleById(id, update, read => read);
308
             return EditSingleById(id, update, read => read);
359
         }
309
         }
360
 
310
 
361
 
311
 
362
-        public LuResult<T> EditSingleById<T>(string id, TDboUpdate update, Func<TDboRead, T> returnFunc)
312
+        public LuResult<T> EditSingleById<T>(TId id, TDboUpdate update, Func<TDboRead, T> returnFunc)
363
         {
313
         {
364
-            var guid = GetGuid(id);
314
+            var guid = GetId(id);
365
             if (guid == null)
315
             if (guid == null)
366
             {
316
             {
367
                 return GetNotFoundResult<T>();
317
                 return GetNotFoundResult<T>();
370
                 model => EditModelFromTUpdate(update, model), list => returnFunc(list.FirstOrDefault()));
320
                 model => EditModelFromTUpdate(update, model), list => returnFunc(list.FirstOrDefault()));
371
         }
321
         }
372
 
322
 
373
-        public LuResult<string> EditSingleByIdGuid(string id, TDboUpdate update)
323
+        public LuResult<TId> EditSingleByIdId(TId id, TDboUpdate update)
374
         {
324
         {
375
-            return EditSingleById(id, update, GetIdFunc<string>());
325
+            return EditSingleById(id, update, GetIdFunc<TId>());
376
         }
326
         }
377
 
327
 
378
-        public LuResult<TDboRead> EditSingleByIdDbo(string id, TDboUpdate update)
328
+        public LuResult<TDboRead> EditSingleByIdDbo(TId id, TDboUpdate update)
379
         {
329
         {
380
             return EditSingleById(id, update, read => read);
330
             return EditSingleById(id, update, read => read);
381
         }
331
         }
396
             });
346
             });
397
         }
347
         }
398
 
348
 
399
-        public LuResult<IEnumerable<string>> DeleteGuid(Expression<Func<TModel, bool>> predicate)
349
+        public LuResult<IEnumerable<TId>> DeleteId(Expression<Func<TModel, bool>> predicate)
400
         {
350
         {
401
-            var func = GetIdFunc<string>();
402
-            return Delete(predicate, reads => reads.Select(func));
403
-        }
404
-
405
-        public LuResult<IEnumerable<long>> DeleteId(Expression<Func<TModel, bool>> predicate)
406
-        {
407
-            var func = GetIdFunc<long>();
351
+            var func = GetIdFunc<TId>();
408
             return Delete(predicate, reads => reads.Select(func));
352
             return Delete(predicate, reads => reads.Select(func));
409
         }
353
         }
410
 
354
 
414
         }
358
         }
415
 
359
 
416
 
360
 
417
-        public LuResult<T> DeleteSingleById<T>(string id, Func<TDboRead, T> returnFunc)
361
+        public LuResult<T> DeleteSingleById<T>(TId id, Func<TDboRead, T> returnFunc)
418
         {
362
         {
419
-            var guid = GetGuid(id);
363
+            var guid = GetId(id);
420
             if (guid == null)
364
             if (guid == null)
421
             {
365
             {
422
                 return GetNotFoundResult<T>();
366
                 return GetNotFoundResult<T>();
425
                 reads => returnFunc(reads.FirstOrDefault()));
369
                 reads => returnFunc(reads.FirstOrDefault()));
426
         }
370
         }
427
 
371
 
428
-        public LuResult<string> DeleteSingleByIdGuid(string id)
429
-        {
430
-            var func = GetIdFunc<string>();
431
-            return DeleteSingleById(id, func);
432
-        }
433
-
434
-        public LuResult<TDboRead> DeleteSingleByIdDbo(string id)
435
-        {
436
-            return DeleteSingleById(id, read => read);
437
-        }
438
-
439
-
440
-        public LuResult<T> DeleteSingleById<T>(long id, Func<TDboRead, T> returnFunc)
441
-        {
442
-            return Delete(GetExpression(new KeyValuePair<string, object>("id", id)),
443
-                reads => returnFunc(reads.First()));
444
-        }
445
-
446
-        public LuResult<long> DeleteSingleByIdId(long id)
372
+        public LuResult<TId> DeleteSingleByIdId(TId id)
447
         {
373
         {
448
-            var func = GetIdFunc<long>();
374
+            var func = GetIdFunc<TId>();
449
             return DeleteSingleById(id, func);
375
             return DeleteSingleById(id, func);
450
         }
376
         }
451
 
377
 
452
-        public LuResult<TDboRead> DeleteSingleByIdDbo(long id)
378
+        public LuResult<TDboRead> DeleteSingleByIdDbo(TId id)
453
         {
379
         {
454
             return DeleteSingleById(id, read => read);
380
             return DeleteSingleById(id, read => read);
455
         }
381
         }

+ 9
- 0
Luticate2.Utils/Hubs/LuNotificationsHub.cs View File

1
+using Microsoft.AspNetCore.SignalR;
2
+
3
+namespace Luticate2.Utils.Hubs
4
+{
5
+    public class LuNotificationsHub : Hub
6
+    {
7
+
8
+    }
9
+}

+ 10
- 31
Luticate2.Utils/Interfaces/ILuCrudInterface.cs View File

8
 
8
 
9
 namespace Luticate2.Utils.Interfaces
9
 namespace Luticate2.Utils.Interfaces
10
 {
10
 {
11
-    public interface ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate>
11
+    public interface ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate, TId>
12
         where TDboCreate : class
12
         where TDboCreate : class
13
         where TDboRead : class
13
         where TDboRead : class
14
         where TDboUpdate : class
14
         where TDboUpdate : class
18
         LuResult<T> Add<T>(TDboCreate obj, Func<TDboRead, T> returnFunc);
18
         LuResult<T> Add<T>(TDboCreate obj, Func<TDboRead, T> returnFunc);
19
 
19
 
20
 
20
 
21
-        LuResult<IEnumerable<string>> AddGuid(IEnumerable<TDboCreate> objs);
21
+        LuResult<IEnumerable<TId>> AddId(IEnumerable<TDboCreate> objs);
22
 
22
 
23
-        LuResult<string> AddGuid(TDboCreate obj);
24
-
25
-
26
-        LuResult<IEnumerable<long>> AddId(IEnumerable<TDboCreate> obj);
27
-
28
-        LuResult<long> AddId(TDboCreate obj);
23
+        LuResult<TId> AddId(TDboCreate obj);
29
 
24
 
30
         LuResult<IEnumerable<TDboRead>> AddDbo(IEnumerable<TDboCreate> obj);
25
         LuResult<IEnumerable<TDboRead>> AddDbo(IEnumerable<TDboCreate> obj);
31
 
26
 
34
 
29
 
35
 
30
 
36
 
31
 
37
-        LuResult<TDboRead> GetSingleById(string id);
38
-
39
-        LuResult<TDboRead> GetSingleById(long id);
32
+        LuResult<TDboRead> GetSingleById(TId id);
40
 
33
 
41
 
34
 
42
         LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, LuFilterDbo filter,
35
         LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, LuFilterDbo filter,
47
 
40
 
48
 
41
 
49
 
42
 
50
-        LuResult<T> EditSingleById<T>(long id, TDboUpdate update, Func<TDboRead, T> returnFunc);
51
-
52
-        LuResult<long> EditSingleByIdId(long id, TDboUpdate update);
53
-
54
-        LuResult<TDboRead> EditSingleByIdDbo(long id, TDboUpdate update);
55
-
56
-
57
-        LuResult<T> EditSingleById<T>(string id, TDboUpdate update, Func<TDboRead, T> returnFunc);
58
-
59
-        LuResult<string> EditSingleByIdGuid(string id, TDboUpdate update);
60
-
61
-        LuResult<TDboRead> EditSingleByIdDbo(string id, TDboUpdate update);
62
-
63
-
43
+        LuResult<T> EditSingleById<T>(TId id, TDboUpdate update, Func<TDboRead, T> returnFunc);
64
 
44
 
45
+        LuResult<TId> EditSingleByIdId(TId id, TDboUpdate update);
65
 
46
 
66
-        LuResult<T> DeleteSingleById<T>(string id, Func<TDboRead, T> returnFunc);
47
+        LuResult<TDboRead> EditSingleByIdDbo(TId id, TDboUpdate update);
67
 
48
 
68
-        LuResult<string> DeleteSingleByIdGuid(string id);
69
 
49
 
70
-        LuResult<TDboRead> DeleteSingleByIdDbo(string id);
71
 
50
 
72
 
51
 
73
-        LuResult<T> DeleteSingleById<T>(long id, Func<TDboRead, T> returnFunc);
52
+        LuResult<T> DeleteSingleById<T>(TId id, Func<TDboRead, T> returnFunc);
74
 
53
 
75
-        LuResult<long> DeleteSingleByIdId(long id);
54
+        LuResult<TId> DeleteSingleByIdId(TId id);
76
 
55
 
77
-        LuResult<TDboRead> DeleteSingleByIdDbo(long id);
56
+        LuResult<TDboRead> DeleteSingleByIdDbo(TId id);
78
     }
57
     }
79
 }
58
 }

+ 0
- 3
TODO View File

1
-fix crud business checks
2
 websockets
1
 websockets
3
 authentication filter
2
 authentication filter
4
-filter dbo
5
-try to generify long/string id
6
 logs
3
 logs
7
 log exceptions in middleware
4
 log exceptions in middleware
8
 LuCrudBusiness check user?
5
 LuCrudBusiness check user?

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

7
 
7
 
8
 namespace Test.Utils.DataAccess
8
 namespace Test.Utils.DataAccess
9
 {
9
 {
10
-    public class LuUtilsPkBigSerialDataAccess : LuEfCrudDataAccess<pk_bigserial, PkBigSerialAddDbo, PkBigSerialDbo, PkBigSerialAddDbo, LuUtilsDbContext>
10
+    public class LuUtilsPkBigSerialDataAccess : LuEfCrudDataAccess<pk_bigserial, PkBigSerialAddDbo, PkBigSerialDbo, PkBigSerialAddDbo, LuUtilsDbContext, long>
11
     {
11
     {
12
         public LuUtilsPkBigSerialDataAccess(LuUtilsDbContext db) : base(db, db.pk_bigserial)
12
         public LuUtilsPkBigSerialDataAccess(LuUtilsDbContext db) : base(db, db.pk_bigserial)
13
         {
13
         {

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

2
 using System.Linq.Expressions;
2
 using System.Linq.Expressions;
3
 using Luticate2.Utils.DataAccess;
3
 using Luticate2.Utils.DataAccess;
4
 using Luticate2.Utils.Dbo.Filter;
4
 using Luticate2.Utils.Dbo.Filter;
5
-using Luticate2.Utils.Utils;
6
 using Test.Utils.DataAccess.Models;
5
 using Test.Utils.DataAccess.Models;
7
 using Test.Utils.Dbo.PkGuid;
6
 using Test.Utils.Dbo.PkGuid;
8
 
7
 
9
 namespace Test.Utils.DataAccess
8
 namespace Test.Utils.DataAccess
10
 {
9
 {
11
-    public class LuUtilsPkGuidDataAccess : LuEfCrudDataAccess<pk_guid, PkGuidAddDbo, PkGuidDbo, PkGuidAddDbo, LuUtilsDbContext>
10
+    public class LuUtilsPkGuidDataAccess : LuEfCrudDataAccess<pk_guid, PkGuidAddDbo, PkGuidDbo, PkGuidAddDbo, LuUtilsDbContext, string>
12
     {
11
     {
13
         public LuUtilsPkGuidDataAccess(LuUtilsDbContext db) : base(db, db.pk_guid)
12
         public LuUtilsPkGuidDataAccess(LuUtilsDbContext db) : base(db, db.pk_guid)
14
         {
13
         {

+ 2
- 2
Test/Utils/EfCrudDataAccess/LuEfCreateDataAccessTest.cs View File

222
                     }
222
                     }
223
                 };
223
                 };
224
                 var service = new LuUtilsPkGuidDataAccess(context);
224
                 var service = new LuUtilsPkGuidDataAccess(context);
225
-                var res = service.AddGuid(dbos);
225
+                var res = service.AddId(dbos);
226
                 Assert.Equal(LuStatus.Success, res.Status);
226
                 Assert.Equal(LuStatus.Success, res.Status);
227
                 foreach (var dbo in dbos.Zip(res.Data, (dbo, serialDbo) => new KeyValuePair<PkGuidAddDbo, string>(dbo, serialDbo)))
227
                 foreach (var dbo in dbos.Zip(res.Data, (dbo, serialDbo) => new KeyValuePair<PkGuidAddDbo, string>(dbo, serialDbo)))
228
                 {
228
                 {
247
             Tests.TestRealDb(context =>
247
             Tests.TestRealDb(context =>
248
             {
248
             {
249
                 var service = new LuUtilsPkGuidDataAccess(context);
249
                 var service = new LuUtilsPkGuidDataAccess(context);
250
-                var res = service.AddGuid(new PkGuidAddDbo
250
+                var res = service.AddId(new PkGuidAddDbo
251
                 {
251
                 {
252
                     SomeInt = 42,
252
                     SomeInt = 42,
253
                     SomeText = "42"
253
                     SomeText = "42"

+ 11
- 14
Test/Utils/EfCrudDataAccess/LuEfDeleteDataAccessTest.cs View File

1
-using System;
2
-using System.Collections.Generic;
1
+using System.Collections.Generic;
3
 using System.Linq;
2
 using System.Linq;
4
-using Luticate2.Utils.Dbo;
5
 using Luticate2.Utils.Dbo.Result;
3
 using Luticate2.Utils.Dbo.Result;
6
 using Test.Utils.DataAccess;
4
 using Test.Utils.DataAccess;
7
 using Test.Utils.Dbo.PkBigSerial;
5
 using Test.Utils.Dbo.PkBigSerial;
8
 using Test.Utils.Dbo.PkGuid;
6
 using Test.Utils.Dbo.PkGuid;
9
 using Xunit;
7
 using Xunit;
10
 
8
 
11
-
12
-namespace Test.Utils.EfCrubDataAccess
9
+namespace Test.Utils.EfCrudDataAccess
13
 {
10
 {
14
     public class LuEfDeleteDataAccessTest
11
     public class LuEfDeleteDataAccessTest
15
     {
12
     {
37
                     }
34
                     }
38
                 };
35
                 };
39
                 var service = new LuUtilsPkGuidDataAccess(context);
36
                 var service = new LuUtilsPkGuidDataAccess(context);
40
-                var res = service.AddGuid(dbos);
37
+                var res = service.AddId(dbos);
41
                 Assert.Equal(LuStatus.Success, res.Status);
38
                 Assert.Equal(LuStatus.Success, res.Status);
42
 
39
 
43
                 var edit = service.Delete(guid => guid.some_int == 42, enumerable => enumerable);
40
                 var edit = service.Delete(guid => guid.some_int == 42, enumerable => enumerable);
88
                     }
85
                     }
89
                 };
86
                 };
90
                 var service = new LuUtilsPkGuidDataAccess(context);
87
                 var service = new LuUtilsPkGuidDataAccess(context);
91
-                var res = service.AddGuid(dbos);
88
+                var res = service.AddId(dbos);
92
                 Assert.Equal(LuStatus.Success, res.Status);
89
                 Assert.Equal(LuStatus.Success, res.Status);
93
 
90
 
94
                 var edit = service.Delete(guid => guid.some_int == 42, enumerable => enumerable.Select(guidDbo => guidDbo.Id));
91
                 var edit = service.Delete(guid => guid.some_int == 42, enumerable => enumerable.Select(guidDbo => guidDbo.Id));
131
                     }
128
                     }
132
                 };
129
                 };
133
                 var service = new LuUtilsPkGuidDataAccess(context);
130
                 var service = new LuUtilsPkGuidDataAccess(context);
134
-                var res = service.AddGuid(dbos);
131
+                var res = service.AddId(dbos);
135
                 Assert.Equal(LuStatus.Success, res.Status);
132
                 Assert.Equal(LuStatus.Success, res.Status);
136
 
133
 
137
-                var edit = service.DeleteGuid(guid => guid.some_int == 42);
134
+                var edit = service.DeleteId(guid => guid.some_int == 42);
138
 
135
 
139
                 Assert.Equal(LuStatus.Success, edit.Status);
136
                 Assert.Equal(LuStatus.Success, edit.Status);
140
                 var elements = edit.Data.ToList();
137
                 var elements = edit.Data.ToList();
217
                     }
214
                     }
218
                 };
215
                 };
219
                 var service = new LuUtilsPkGuidDataAccess(context);
216
                 var service = new LuUtilsPkGuidDataAccess(context);
220
-                var res = service.AddGuid(dbos);
217
+                var res = service.AddId(dbos);
221
                 Assert.Equal(LuStatus.Success, res.Status);
218
                 Assert.Equal(LuStatus.Success, res.Status);
222
 
219
 
223
                 var edit = service.DeleteDbo(guid => guid.some_int == 42);
220
                 var edit = service.DeleteDbo(guid => guid.some_int == 42);
268
                     }
265
                     }
269
                 };
266
                 };
270
                 var service = new LuUtilsPkGuidDataAccess(context);
267
                 var service = new LuUtilsPkGuidDataAccess(context);
271
-                var res = service.AddGuid(dbos);
268
+                var res = service.AddId(dbos);
272
                 Assert.Equal(LuStatus.Success, res.Status);
269
                 Assert.Equal(LuStatus.Success, res.Status);
273
 
270
 
274
                 var ids = res.Data.ToList();
271
                 var ids = res.Data.ToList();
315
                     }
312
                     }
316
                 };
313
                 };
317
                 var service = new LuUtilsPkGuidDataAccess(context);
314
                 var service = new LuUtilsPkGuidDataAccess(context);
318
-                var res = service.AddGuid(dbos);
315
+                var res = service.AddId(dbos);
319
                 Assert.Equal(LuStatus.Success, res.Status);
316
                 Assert.Equal(LuStatus.Success, res.Status);
320
 
317
 
321
                 var ids = res.Data.ToList();
318
                 var ids = res.Data.ToList();
322
 
319
 
323
-                var edit = service.DeleteSingleByIdGuid(ids[0]);
320
+                var edit = service.DeleteSingleByIdId(ids[0]);
324
                 Assert.Equal(LuStatus.Success, edit.Status);
321
                 Assert.Equal(LuStatus.Success, edit.Status);
325
 
322
 
326
                 var get = service.GetMultiple(guid => guid.some_text);
323
                 var get = service.GetMultiple(guid => guid.some_text);
360
                     }
357
                     }
361
                 };
358
                 };
362
                 var service = new LuUtilsPkGuidDataAccess(context);
359
                 var service = new LuUtilsPkGuidDataAccess(context);
363
-                var res = service.AddGuid(dbos);
360
+                var res = service.AddId(dbos);
364
                 Assert.Equal(LuStatus.Success, res.Status);
361
                 Assert.Equal(LuStatus.Success, res.Status);
365
 
362
 
366
                 var ids = res.Data.ToList();
363
                 var ids = res.Data.ToList();

+ 8
- 8
Test/Utils/EfCrudDataAccess/LuEfReadDataAccessTest.cs View File

143
             Tests.TestRealDb(context =>
143
             Tests.TestRealDb(context =>
144
             {
144
             {
145
                 var service = new LuUtilsPkGuidDataAccess(context);
145
                 var service = new LuUtilsPkGuidDataAccess(context);
146
-                var res = service.AddGuid(new PkGuidAddDbo
146
+                var res = service.AddId(new PkGuidAddDbo
147
                 {
147
                 {
148
                     SomeInt = 42,
148
                     SomeInt = 42,
149
                     SomeText = "42"
149
                     SomeText = "42"
165
             Tests.TestRealDb(context =>
165
             Tests.TestRealDb(context =>
166
             {
166
             {
167
                 var service = new LuUtilsPkGuidDataAccess(context);
167
                 var service = new LuUtilsPkGuidDataAccess(context);
168
-                var res = service.AddGuid(new PkGuidAddDbo
168
+                var res = service.AddId(new PkGuidAddDbo
169
                 {
169
                 {
170
                     SomeInt = 42,
170
                     SomeInt = 42,
171
                     SomeText = "42"
171
                     SomeText = "42"
202
                     }
202
                     }
203
                 };
203
                 };
204
                 var service = new LuUtilsPkGuidDataAccess(context);
204
                 var service = new LuUtilsPkGuidDataAccess(context);
205
-                var res = service.AddGuid(dbos);
205
+                var res = service.AddId(dbos);
206
                 Assert.Equal(LuStatus.Success, res.Status);
206
                 Assert.Equal(LuStatus.Success, res.Status);
207
 
207
 
208
                 var get = service.GetMultiple(table => table.OrderBy(guid => guid.some_int),
208
                 var get = service.GetMultiple(table => table.OrderBy(guid => guid.some_int),
245
                     }
245
                     }
246
                 };
246
                 };
247
                 var service = new LuUtilsPkGuidDataAccess(context);
247
                 var service = new LuUtilsPkGuidDataAccess(context);
248
-                var res = service.AddGuid(dbos);
248
+                var res = service.AddId(dbos);
249
                 Assert.Equal(LuStatus.Success, res.Status);
249
                 Assert.Equal(LuStatus.Success, res.Status);
250
 
250
 
251
                 var get = service.GetMultiple(guid => guid.some_int, guid => guid.some_int == 42, 0, int.MaxValue,
251
                 var get = service.GetMultiple(guid => guid.some_int, guid => guid.some_int == 42, 0, int.MaxValue,
288
                     }
288
                     }
289
                 };
289
                 };
290
                 var service = new LuUtilsPkGuidDataAccess(context);
290
                 var service = new LuUtilsPkGuidDataAccess(context);
291
-                var res = service.AddGuid(dbos);
291
+                var res = service.AddId(dbos);
292
                 Assert.Equal(LuStatus.Success, res.Status);
292
                 Assert.Equal(LuStatus.Success, res.Status);
293
 
293
 
294
                 var get = service.GetMultiple(table => table.OrderBy(guid => guid.some_int), 0, int.MaxValue,
294
                 var get = service.GetMultiple(table => table.OrderBy(guid => guid.some_int), 0, int.MaxValue,
335
                     }
335
                     }
336
                 };
336
                 };
337
                 var service = new LuUtilsPkGuidDataAccess(context);
337
                 var service = new LuUtilsPkGuidDataAccess(context);
338
-                var res = service.AddGuid(dbos);
338
+                var res = service.AddId(dbos);
339
                 Assert.Equal(LuStatus.Success, res.Status);
339
                 Assert.Equal(LuStatus.Success, res.Status);
340
 
340
 
341
                 var get = service.GetMultiple(guid => guid.some_int, 0, int.MaxValue, guid => guid.some_text);
341
                 var get = service.GetMultiple(guid => guid.some_int, 0, int.MaxValue, guid => guid.some_text);
381
                     }
381
                     }
382
                 };
382
                 };
383
                 var service = new LuUtilsPkGuidDataAccess(context);
383
                 var service = new LuUtilsPkGuidDataAccess(context);
384
-                var res = service.AddGuid(dbos);
384
+                var res = service.AddId(dbos);
385
                 Assert.Equal(LuStatus.Success, res.Status);
385
                 Assert.Equal(LuStatus.Success, res.Status);
386
 
386
 
387
                 var orderBy = LuOrderByBinder.FromString("someInt,someText");
387
                 var orderBy = LuOrderByBinder.FromString("someInt,someText");
430
                     }
430
                     }
431
                 };
431
                 };
432
                 var service = new LuUtilsPkGuidDataAccess(context);
432
                 var service = new LuUtilsPkGuidDataAccess(context);
433
-                var res = service.AddGuid(dbos);
433
+                var res = service.AddId(dbos);
434
                 Assert.Equal(LuStatus.Success, res.Status);
434
                 Assert.Equal(LuStatus.Success, res.Status);
435
 
435
 
436
                 var orderBy = LuOrderByBinder.FromString("someText:desc,someInt");
436
                 var orderBy = LuOrderByBinder.FromString("someText:desc,someInt");

+ 14
- 15
Test/Utils/EfCrudDataAccess/LuEfUpdateDataAccessTest.cs View File

1
 using System;
1
 using System;
2
 using System.Collections.Generic;
2
 using System.Collections.Generic;
3
 using System.Linq;
3
 using System.Linq;
4
-using Luticate2.Utils.Dbo;
5
 using Luticate2.Utils.Dbo.Result;
4
 using Luticate2.Utils.Dbo.Result;
6
 using Test.Utils.DataAccess;
5
 using Test.Utils.DataAccess;
7
 using Test.Utils.Dbo.PkBigSerial;
6
 using Test.Utils.Dbo.PkBigSerial;
8
 using Test.Utils.Dbo.PkGuid;
7
 using Test.Utils.Dbo.PkGuid;
9
 using Xunit;
8
 using Xunit;
10
 
9
 
11
-namespace Test.Utils.EfCrubDataAccess
10
+namespace Test.Utils.EfCrudDataAccess
12
 {
11
 {
13
     public class LuEfUpdateDataAccessTest
12
     public class LuEfUpdateDataAccessTest
14
     {
13
     {
36
                     }
35
                     }
37
                 };
36
                 };
38
                 var service = new LuUtilsPkGuidDataAccess(context);
37
                 var service = new LuUtilsPkGuidDataAccess(context);
39
-                var res = service.AddGuid(dbos);
38
+                var res = service.AddId(dbos);
40
                 Assert.Equal(LuStatus.Success, res.Status);
39
                 Assert.Equal(LuStatus.Success, res.Status);
41
 
40
 
42
                 var edit = service.Edit(guid => guid.some_int == 42, guid => guid.some_int = -1, enumerable => enumerable);
41
                 var edit = service.Edit(guid => guid.some_int == 42, guid => guid.some_int = -1, enumerable => enumerable);
79
                     }
78
                     }
80
                 };
79
                 };
81
                 var service = new LuUtilsPkGuidDataAccess(context);
80
                 var service = new LuUtilsPkGuidDataAccess(context);
82
-                var res = service.AddGuid(dbos);
81
+                var res = service.AddId(dbos);
83
                 Assert.Equal(LuStatus.Success, res.Status);
82
                 Assert.Equal(LuStatus.Success, res.Status);
84
 
83
 
85
                 var edit = service.Edit(guid => guid.some_int == 42, guid => guid.some_int = -1, enumerable => enumerable.Select(guidDbo => guidDbo.SomeText));
84
                 var edit = service.Edit(guid => guid.some_int == 42, guid => guid.some_int = -1, enumerable => enumerable.Select(guidDbo => guidDbo.SomeText));
120
                     }
119
                     }
121
                 };
120
                 };
122
                 var service = new LuUtilsPkGuidDataAccess(context);
121
                 var service = new LuUtilsPkGuidDataAccess(context);
123
-                var res = service.AddGuid(dbos);
122
+                var res = service.AddId(dbos);
124
                 Assert.Equal(LuStatus.Success, res.Status);
123
                 Assert.Equal(LuStatus.Success, res.Status);
125
 
124
 
126
-                var edit = service.EditGuid(guid => guid.some_int == 42, guid => guid.some_int = -1);
125
+                var edit = service.EditId(guid => guid.some_int == 42, guid => guid.some_int = -1);
127
 
126
 
128
                 Assert.Equal(LuStatus.Success, edit.Status);
127
                 Assert.Equal(LuStatus.Success, edit.Status);
129
                 var elements = edit.Data.ToList();
128
                 var elements = edit.Data.ToList();
202
                     }
201
                     }
203
                 };
202
                 };
204
                 var service = new LuUtilsPkGuidDataAccess(context);
203
                 var service = new LuUtilsPkGuidDataAccess(context);
205
-                var res = service.AddGuid(dbos);
204
+                var res = service.AddId(dbos);
206
                 Assert.Equal(LuStatus.Success, res.Status);
205
                 Assert.Equal(LuStatus.Success, res.Status);
207
 
206
 
208
                 var edit = service.EditDbo(guid => guid.some_int == 42, guid => guid.some_int = -1);
207
                 var edit = service.EditDbo(guid => guid.some_int == 42, guid => guid.some_int = -1);
400
                     }
399
                     }
401
                 };
400
                 };
402
                 var service = new LuUtilsPkGuidDataAccess(context);
401
                 var service = new LuUtilsPkGuidDataAccess(context);
403
-                var res = service.AddGuid(dbos);
402
+                var res = service.AddId(dbos);
404
                 Assert.Equal(LuStatus.Success, res.Status);
403
                 Assert.Equal(LuStatus.Success, res.Status);
405
                 var ids = res.Data.ToList();
404
                 var ids = res.Data.ToList();
406
 
405
 
452
                     }
451
                     }
453
                 };
452
                 };
454
                 var service = new LuUtilsPkGuidDataAccess(context);
453
                 var service = new LuUtilsPkGuidDataAccess(context);
455
-                var res = service.AddGuid(dbos);
454
+                var res = service.AddId(dbos);
456
                 Assert.Equal(LuStatus.Success, res.Status);
455
                 Assert.Equal(LuStatus.Success, res.Status);
457
                 var ids = res.Data.ToList();
456
                 var ids = res.Data.ToList();
458
 
457
 
459
-                var edit = service.EditSingleByIdGuid(ids[0], guid => guid.some_int = -1);
458
+                var edit = service.EditSingleByIdId(ids[0], guid => guid.some_int = -1);
460
                 Assert.Equal(LuStatus.Success, edit.Status);
459
                 Assert.Equal(LuStatus.Success, edit.Status);
461
 
460
 
462
                 var get = service.GetMultiple(guid => guid.some_text);
461
                 var get = service.GetMultiple(guid => guid.some_text);
502
                     }
501
                     }
503
                 };
502
                 };
504
                 var service = new LuUtilsPkGuidDataAccess(context);
503
                 var service = new LuUtilsPkGuidDataAccess(context);
505
-                var res = service.AddGuid(dbos);
504
+                var res = service.AddId(dbos);
506
                 Assert.Equal(LuStatus.Success, res.Status);
505
                 Assert.Equal(LuStatus.Success, res.Status);
507
                 var ids = res.Data.ToList();
506
                 var ids = res.Data.ToList();
508
 
507
 
714
                     }
713
                     }
715
                 };
714
                 };
716
                 var service = new LuUtilsPkGuidDataAccess(context);
715
                 var service = new LuUtilsPkGuidDataAccess(context);
717
-                var res = service.AddGuid(dbos);
716
+                var res = service.AddId(dbos);
718
                 Assert.Equal(LuStatus.Success, res.Status);
717
                 Assert.Equal(LuStatus.Success, res.Status);
719
                 var ids = res.Data.ToList();
718
                 var ids = res.Data.ToList();
720
 
719
 
768
                     }
767
                     }
769
                 };
768
                 };
770
                 var service = new LuUtilsPkGuidDataAccess(context);
769
                 var service = new LuUtilsPkGuidDataAccess(context);
771
-                var res = service.AddGuid(dbos);
770
+                var res = service.AddId(dbos);
772
                 Assert.Equal(LuStatus.Success, res.Status);
771
                 Assert.Equal(LuStatus.Success, res.Status);
773
                 var ids = res.Data.ToList();
772
                 var ids = res.Data.ToList();
774
 
773
 
775
                 dbos[0].SomeInt = -1;
774
                 dbos[0].SomeInt = -1;
776
 
775
 
777
-                var edit = service.EditSingleByIdGuid(ids[0], dbos[0]);
776
+                var edit = service.EditSingleByIdId(ids[0], dbos[0]);
778
                 Assert.Equal(LuStatus.Success, edit.Status);
777
                 Assert.Equal(LuStatus.Success, edit.Status);
779
 
778
 
780
                 var get = service.GetMultiple(guid => guid.some_text);
779
                 var get = service.GetMultiple(guid => guid.some_text);
820
                     }
819
                     }
821
                 };
820
                 };
822
                 var service = new LuUtilsPkGuidDataAccess(context);
821
                 var service = new LuUtilsPkGuidDataAccess(context);
823
-                var res = service.AddGuid(dbos);
822
+                var res = service.AddId(dbos);
824
                 Assert.Equal(LuStatus.Success, res.Status);
823
                 Assert.Equal(LuStatus.Success, res.Status);
825
                 var ids = res.Data.ToList();
824
                 var ids = res.Data.ToList();
826
 
825
 

+ 7
- 2
WebTest/Business/PkGuidBusiness.cs View File

6
 
6
 
7
 namespace WebTest.Business
7
 namespace WebTest.Business
8
 {
8
 {
9
-    public class PkGuidBusiness : LuCrudBusiness<LuUtilsPkGuidDataAccess, PkGuidAddDbo, PkGuidDbo, PkGuidAddDbo>
9
+    public class PkGuidBusiness : LuCrudBusiness<LuUtilsPkGuidDataAccess, PkGuidAddDbo, PkGuidDbo, PkGuidAddDbo, string>
10
     {
10
     {
11
-        public PkGuidBusiness(LuUtilsPkGuidDataAccess dataAccess) : base(dataAccess)
11
+        private readonly LuNotificationsBusiness _notificationsBusiness;
12
+
13
+        public PkGuidBusiness(LuUtilsPkGuidDataAccess dataAccess, LuNotificationsBusiness notificationsBusiness) : base(dataAccess)
12
         {
14
         {
15
+            _notificationsBusiness = notificationsBusiness;
13
         }
16
         }
14
 
17
 
15
         protected override LuResult<PkGuidAddDbo> CheckAdd(PkGuidAddDbo obj)
18
         protected override LuResult<PkGuidAddDbo> CheckAdd(PkGuidAddDbo obj)
29
             }
32
             }
30
             return LuResult<PkGuidAddDbo>.Ok(update);
33
             return LuResult<PkGuidAddDbo>.Ok(update);
31
         }
34
         }
35
+
36
+
32
     }
37
     }
33
 }
38
 }

+ 1
- 1
WebTest/Controllers/PkGuidController.cs View File

4
 
4
 
5
 namespace WebTest.Controllers
5
 namespace WebTest.Controllers
6
 {
6
 {
7
-    public class PkGuidController : LuCrudController<PkGuidBusiness, PkGuidAddDbo, PkGuidDbo, PkGuidAddDbo>
7
+    public class PkGuidController : LuCrudController<PkGuidBusiness, PkGuidAddDbo, PkGuidDbo, PkGuidAddDbo, string>
8
     {
8
     {
9
         public PkGuidController(PkGuidBusiness busines) : base(busines)
9
         public PkGuidController(PkGuidBusiness busines) : base(busines)
10
         {
10
         {

Loading…
Cancel
Save