Beispiel #1
0
        public void Save()
        {
            foreach (T newObj in NewObjects)
            {
                Storage.Add(newObj);
            }

            foreach (T deletedObj in RemovedIds.Select(id => this.Find(id)))
            {
                Storage.Remove(deletedObj);
            }

            Storage.Save();
        }
Beispiel #2
0
        public ChangeSet(ValueChange <TParentToken> parentToken, ValueChange <IEnumerable <TChildToken> > childTokens)
        {
            OldIds = Ids(childTokens.OldValue).ToArray();
            NewIds = Ids(childTokens.NewValue).ToArray();

            RemovedIds    = Ids(ExceptIds(childTokens.OldValue, NewIds)).ToArray();
            AddedIds      = Ids(ExceptIds(childTokens.NewValue, OldIds)).ToArray();
            PersistentIds = NewIds.Intersect(OldIds).ToArray();

            var persistedOld   = IntersectIds(childTokens.OldValue, PersistentIds).OrderBy(t => t.Id);
            var persistedNew   = IntersectIds(childTokens.NewValue, PersistentIds).OrderBy(t => t.Id);
            var persistedPairs = persistedOld.Zip(persistedNew, ValueChange.Create);

            Diffs = persistedPairs.Where(vc => vc.IsChanged()).ToArray();

            AddedChanges   = AddedIds.Select(id => Change.Added(parentToken.NewValue.Id, id)).ToArray();
            RemovedChanges = RemovedIds.Select(id => Change.Removed(parentToken.NewValue.Id, id)).ToArray();
        }