public SimpleParentChildResultSet SubmitChanges(ClientInfo clientInfo, SimpleParentChildChangeSet changeSet) { var resultSet = new SimpleParentChildResultSet(changeSet); using (var transactionScope = CreateSavingTransactionScope()) { using (var dataRepository = _repositoryFactory(clientInfo)) { // optional custom processing PreProcessing(clientInfo, ref changeSet, dataRepository); // apply chnages to repository ApplyChanges(dataRepository, dataRepository.ParentSet, changeSet, changeSet.ParentSet, clientInfo); ApplyChanges(dataRepository, dataRepository.ChildSet, changeSet, changeSet.ChildSet, clientInfo); // optional custom processing BeforeSaving(clientInfo, ref changeSet, dataRepository); // save changes SaveChanges(dataRepository, changeSet, resultSet); // optional custom processing PostProcessing(clientInfo, ref resultSet, dataRepository); } transactionScope.Complete(); } return(resultSet); }
public SimpleParentChildChangeSet CreateChangeSet(IEnumerable <Parent> parentSet, IEnumerable <Child> childSet) { // retrieve changes sets (modified entities) var parentChangeSet = GetChangeSet(parentSet); var childChangeSet = GetChangeSet(childSet); // reduce entities (copy changed values) var parentSetMap = ReduceToModifications(parentChangeSet); var childSetMap = ReduceToModifications(childChangeSet); // fixup relations (replaces related entities with reduced entites) FixupRelations( CastToEntityTuple(parentSetMap), CastToEntityTuple(childSetMap) ); var changeSet = new SimpleParentChildChangeSet(); if (parentSetMap.Count > 0) { changeSet.ParentSet = parentSetMap.Select(e => e.ReducedEntity).ToList(); } if (childSetMap.Count > 0) { changeSet.ChildSet = childSetMap.Select(e => e.ReducedEntity).ToList(); } return(changeSet); }
partial void BeforeSaving(ClientInfo clientInfo, ref SimpleParentChildChangeSet changeSet, ISimpleParentChildRepository repository);
partial void PreProcessing(ClientInfo clientInfo, ref SimpleParentChildChangeSet changeSet, ISimpleParentChildRepository repository);