Selaa lähdekoodia

[WebApiUtils] Fixed AddDbo

feature/authentication-tests
Robin Thoni 9 vuotta sitten
vanhempi
commit
004c2cd5e1
1 muutettua tiedostoa jossa 19 lisäystä ja 16 poistoa
  1. 19
    16
      WebApiUtils/BusinessManager/SqlServerManager.cs

+ 19
- 16
WebApiUtils/BusinessManager/SqlServerManager.cs Näytä tiedosto

@@ -30,8 +30,17 @@ namespace iiie.WebApiUtils.BusinessManager
30 30
         /// Convert a DBO to DB object
31 31
         /// </summary>
32 32
         /// <param name="obj">The object to be converted</param>
33
+        /// <param name="add">The object to be added</param>
33 34
         /// <returns>The DB object</returns>
34
-        public abstract OpResult<TDbObject> DboAddToDb(TDboAdd obj);
35
+        public abstract OpResult<bool> DboAddToDb(TDboAdd obj, TDbObject add);
36
+
37
+        /// <summary>
38
+        /// Convert a DBO to DB object
39
+        /// </summary>
40
+        /// <param name="obj">The object to be converted</param>
41
+        /// <param name="edit">The object beeing edited</param>
42
+        /// <returns>The DB object</returns>
43
+        public abstract OpResult<bool> DboEditToDb(TDboEdit obj, TDbObject edit);
35 44
 
36 45
         /// <summary>
37 46
         /// Return a global predicate that will be applied to all selects
@@ -42,14 +51,6 @@ namespace iiie.WebApiUtils.BusinessManager
42 51
             return x => true;
43 52
         }
44 53
 
45
-        /// <summary>
46
-        /// Convert a DBO to DB object
47
-        /// </summary>
48
-        /// <param name="obj">The object to be converted</param>
49
-        /// <param name="edit">The object beeing edited</param>
50
-        /// <returns>The DB object</returns>
51
-        public abstract OpResult<TDbObject> DboEditToDb(TDboEdit obj, TDbObject edit);
52
-
53 54
         /// <summary>
54 55
         /// Helper to get real select predicate
55 56
         /// </summary>
@@ -75,11 +76,12 @@ namespace iiie.WebApiUtils.BusinessManager
75 76
         /// Helper to convert DBO object to DB
76 77
         /// </summary>
77 78
         /// <param name="res">The result to convert</param>
79
+        /// <param name="add">The object to be added</param>
78 80
         /// <returns>The DB object</returns>
79
-        public static OpResult<TDbObject> DboAddToDbStatic(TDboAdd res)
81
+        public static OpResult<bool> DboAddToDbStatic(TDboAdd res, TDbObject add)
80 82
         {
81 83
             var obj = new TThis();
82
-            return obj.DboAddToDb(res);
84
+            return obj.DboAddToDb(res, add);
83 85
         }
84 86
 
85 87
         /// <summary>
@@ -88,7 +90,7 @@ namespace iiie.WebApiUtils.BusinessManager
88 90
         /// <param name="res">The result to convert</param>
89 91
         /// <param name="edit">The object beeing edited</param>
90 92
         /// <returns>The DB object</returns>
91
-        public static OpResult<TDbObject> DboEditToDbStatic(TDboEdit res, TDbObject edit)
93
+        public static OpResult<bool> DboEditToDbStatic(TDboEdit res, TDbObject edit)
92 94
         {
93 95
             var obj = new TThis();
94 96
             return obj.DboEditToDb(res, edit);
@@ -196,12 +198,13 @@ namespace iiie.WebApiUtils.BusinessManager
196 198
         {
197 199
             return Execute((db, table) =>
198 200
             {
199
-                var item = DboAddToDbStatic(obj);
201
+                var add = table.Create();
202
+                var item = DboAddToDbStatic(obj, add);
200 203
                 if (!item)
201 204
                     return item.To<T>();
202
-                var insertedObj = table.Add(item.Data);
205
+                table.Add(add);
203 206
                 db.SaveChanges();
204
-                var res = returnFunc.Compile().DynamicInvoke(insertedObj);
207
+                var res = returnFunc.Compile().DynamicInvoke(add);
205 208
                 return OpResult<T>.Ok((T)res);
206 209
             });
207 210
         }
@@ -255,7 +258,7 @@ namespace iiie.WebApiUtils.BusinessManager
255 258
                 var res = DboEditToDbStatic(obj, edit.Data);
256 259
                 if (!res)
257 260
                     return res.To<bool>();
258
-                db.Entry(edit.Data).CurrentValues.SetValues(res.Data);
261
+                db.Entry(edit.Data).CurrentValues.SetValues(edit.Data);
259 262
                 db.SaveChanges();
260 263
                 return OpResult<bool>.Ok(true);
261 264
             });

Loading…
Peruuta
Tallenna