Browse Source

[WebApiUtils] Fixed AddDbo

feature/authentication-tests
Robin Thoni 9 years ago
parent
commit
004c2cd5e1
1 changed files with 19 additions and 16 deletions
  1. 19
    16
      WebApiUtils/BusinessManager/SqlServerManager.cs

+ 19
- 16
WebApiUtils/BusinessManager/SqlServerManager.cs View File

30
         /// Convert a DBO to DB object
30
         /// Convert a DBO to DB object
31
         /// </summary>
31
         /// </summary>
32
         /// <param name="obj">The object to be converted</param>
32
         /// <param name="obj">The object to be converted</param>
33
+        /// <param name="add">The object to be added</param>
33
         /// <returns>The DB object</returns>
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
         /// <summary>
45
         /// <summary>
37
         /// Return a global predicate that will be applied to all selects
46
         /// Return a global predicate that will be applied to all selects
42
             return x => true;
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
         /// <summary>
54
         /// <summary>
54
         /// Helper to get real select predicate
55
         /// Helper to get real select predicate
55
         /// </summary>
56
         /// </summary>
75
         /// Helper to convert DBO object to DB
76
         /// Helper to convert DBO object to DB
76
         /// </summary>
77
         /// </summary>
77
         /// <param name="res">The result to convert</param>
78
         /// <param name="res">The result to convert</param>
79
+        /// <param name="add">The object to be added</param>
78
         /// <returns>The DB object</returns>
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
             var obj = new TThis();
83
             var obj = new TThis();
82
-            return obj.DboAddToDb(res);
84
+            return obj.DboAddToDb(res, add);
83
         }
85
         }
84
 
86
 
85
         /// <summary>
87
         /// <summary>
88
         /// <param name="res">The result to convert</param>
90
         /// <param name="res">The result to convert</param>
89
         /// <param name="edit">The object beeing edited</param>
91
         /// <param name="edit">The object beeing edited</param>
90
         /// <returns>The DB object</returns>
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
             var obj = new TThis();
95
             var obj = new TThis();
94
             return obj.DboEditToDb(res, edit);
96
             return obj.DboEditToDb(res, edit);
196
         {
198
         {
197
             return Execute((db, table) =>
199
             return Execute((db, table) =>
198
             {
200
             {
199
-                var item = DboAddToDbStatic(obj);
201
+                var add = table.Create();
202
+                var item = DboAddToDbStatic(obj, add);
200
                 if (!item)
203
                 if (!item)
201
                     return item.To<T>();
204
                     return item.To<T>();
202
-                var insertedObj = table.Add(item.Data);
205
+                table.Add(add);
203
                 db.SaveChanges();
206
                 db.SaveChanges();
204
-                var res = returnFunc.Compile().DynamicInvoke(insertedObj);
207
+                var res = returnFunc.Compile().DynamicInvoke(add);
205
                 return OpResult<T>.Ok((T)res);
208
                 return OpResult<T>.Ok((T)res);
206
             });
209
             });
207
         }
210
         }
255
                 var res = DboEditToDbStatic(obj, edit.Data);
258
                 var res = DboEditToDbStatic(obj, edit.Data);
256
                 if (!res)
259
                 if (!res)
257
                     return res.To<bool>();
260
                     return res.To<bool>();
258
-                db.Entry(edit.Data).CurrentValues.SetValues(res.Data);
261
+                db.Entry(edit.Data).CurrentValues.SetValues(edit.Data);
259
                 db.SaveChanges();
262
                 db.SaveChanges();
260
                 return OpResult<bool>.Ok(true);
263
                 return OpResult<bool>.Ok(true);
261
             });
264
             });

Loading…
Cancel
Save