예제 #1
0
        /// <summary>Translates session unit of work to CouchApi bulk update unit of work.</summary>
        public bool ApplyChanges(IBulkUpdateBatch work)
        {
            if (work == null) throw new ArgumentNullException("work");

            bool haveChanged = false;
            foreach (var documentEntity in entityMap.Values)
            {
                if (documentEntity.HaveRemoved)
                {
                    if (documentEntity.HavePersisted)
                    {
                        work.Delete(documentEntity.DocumentId, documentEntity.Revision);
                        haveChanged = true;
                    }
                }
                else
                {
                    var changed = documentEntity.MapIfChanged();
                    if (!documentEntity.HavePersisted)
                    {
                        work.Create(documentEntity.Document);
                        haveChanged = true;
                    }
                    else if (changed)
                    {
                        work.Update(documentEntity.Document);
                        haveChanged = true;
                    }
                }
            }
            return haveChanged;
        }
예제 #2
0
        /// <summary>Translates session unit of work to CouchApi bulk update unit of work.</summary>
        public bool ApplyChanges(IBulkUpdateBatch work)
        {
            if (work == null)
            {
                throw new ArgumentNullException("work");
            }

            bool haveChanged = false;

            foreach (var documentEntity in entityMap.Values)
            {
                if (documentEntity.HaveRemoved)
                {
                    if (documentEntity.HavePersisted)
                    {
                        work.Delete(documentEntity.DocumentId, documentEntity.Revision);
                        haveChanged = true;
                    }
                }
                else
                {
                    var changed = documentEntity.MapIfChanged();
                    if (!documentEntity.HavePersisted)
                    {
                        work.Create(documentEntity.Document);
                        haveChanged = true;
                    }
                    else if (changed)
                    {
                        work.Update(documentEntity.Document);
                        haveChanged = true;
                    }
                }
            }
            return(haveChanged);
        }