Exemple #1
0
        public NTierDemoResultSet SubmitChanges(ClientInfo clientInfo, NTierDemoChangeSet changeSet)
        {
            var resultSet = new NTierDemoResultSet(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.Users, changeSet, changeSet.Users, clientInfo);
                    ApplyChanges(dataRepository, dataRepository.Blogs, changeSet, changeSet.Blogs, clientInfo);
                    ApplyChanges(dataRepository, dataRepository.Posts, changeSet, changeSet.Posts, 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 NTierDemoChangeSet CreateChangeSet(IEnumerable <User> users, IEnumerable <Blog> blogs, IEnumerable <Post> posts)
        {
            // retrieve changes sets (modified entities)
            var userChangeSet = GetChangeSet(users);
            var blogChangeSet = GetChangeSet(blogs);
            var postChangeSet = GetChangeSet(posts);

            // reduce entities (copy changed values)
            var usersMap = ReduceToModifications(userChangeSet);
            var blogsMap = ReduceToModifications(blogChangeSet);
            var postsMap = ReduceToModifications(postChangeSet);

            // fixup relations (replaces related entities with reduced entites)
            FixupRelations(
                CastToEntityTuple(usersMap),
                CastToEntityTuple(blogsMap),
                CastToEntityTuple(postsMap)
                );

            var changeSet = new NTierDemoChangeSet();

            if (usersMap.Count > 0)
            {
                changeSet.Users = usersMap.Select(e => e.ReducedEntity).ToList();
            }
            if (blogsMap.Count > 0)
            {
                changeSet.Blogs = blogsMap.Select(e => e.ReducedEntity).ToList();
            }
            if (postsMap.Count > 0)
            {
                changeSet.Posts = postsMap.Select(e => e.ReducedEntity).ToList();
            }

            return(changeSet);
        }
Exemple #3
0
 partial void BeforeSaving(ClientInfo clientInfo, ref NTierDemoChangeSet changeSet, INTierDemoRepository repository);
Exemple #4
0
 partial void PreProcessing(ClientInfo clientInfo, ref NTierDemoChangeSet changeSet, INTierDemoRepository repository);