Browse Source

added SyncManyToMany method

tags/v0.3.0
Robin Thoni 8 years ago
parent
commit
c64f91535a
1 changed files with 12 additions and 0 deletions
  1. 12
    0
      Luticate2.Utils/DataAccess/LuEfCrudDataAccess.cs

+ 12
- 0
Luticate2.Utils/DataAccess/LuEfCrudDataAccess.cs View File

@@ -372,6 +372,18 @@ namespace Luticate2.Utils.DataAccess
372 372
 //            return EditSingleById(id, update, read => read);
373 373
 //        }
374 374
 
375
+        protected void SyncManyToMany<T>(IList<TId> ids, IList<T> verbs, Func<TId, T> newVerb, Func<T, TId> getVerbFk)
376
+        {
377
+            foreach (var added in ids.Where(id => verbs.FirstOrDefault(o => Equals(getVerbFk(o), id)) == null))
378
+            {
379
+                verbs.Add(newVerb(added));
380
+            }
381
+            foreach (var removed in verbs.Where(v => ids.FirstOrDefault(id => Equals(getVerbFk(v), id)) == null).ToList())
382
+            {
383
+                verbs.Remove(removed);
384
+            }
385
+        }
386
+
375 387
         protected virtual LuResult<bool> _EditSingleById(TModel model, TDboUpdate update, TDbContext db, DbSet<TModel> table)
376 388
         {
377 389
             return LuResult<bool>.Ok(true);

Loading…
Cancel
Save