Exemple #1
0
        public override void AcceptChanges()
        {
            var eventAggregator = Container.Resolve <IEventAggregator>();

            //удаленные из спецификации группы
            _removedUnits.ForEach(x => { x.RejectChanges(); });
            _removedUnits.ForEach(x => { x.Specification = null; });
            _removedUnits.ForEach(x => { x.AcceptChanges(); });

            //удаленные из спецификации группы
            var removed = Groups.Where(x => x.Groups != null).SelectMany(x => x.Groups.RemovedItems).ToList();

            removed = Groups.RemovedItems.Concat(removed).ToList();
            removed.ForEach(x => { x.RejectChanges(); });
            removed.ForEach(x => { x.Specification = null; });
            removed.ForEach(x => { x.AcceptChanges(); });

            var added    = GetAddedUnits().ToList();
            var modified = Groups.Where(x => x.Groups != null).SelectMany(x => x.Groups.ModifiedItems).ToList();

            modified = modified.Concat(Groups.ModifiedItems).ToList();

            Groups.AcceptChanges();

            _groupsToReject.RejectChanges();

            added.Concat(modified.Select(x => x.Model)).Distinct().ForEach(x => eventAggregator.GetEvent <AfterSaveSalesUnitEvent>().Publish(x));
        }
        public virtual void AcceptChanges()
        {
            var eventAggregator = Container.Resolve <IEventAggregator>();

            //добавляем созданные
            var added = GetAddedUnits().ToList();

            UnitOfWork.Repository <TModel>().AddRange(added);

            //удаляем удаленные
            var removedModels = GetUnitsForTotalRemove().ToList();

            //сообщаем об удалении (так высоко, т.к. после удаления объект рушится)
            removedModels.ForEach(x => eventAggregator.GetEvent <TAfterRemoveEvent>().Publish(x));
            UnitOfWork.Repository <TModel>().DeleteRange(removedModels);

            var modified = Groups.Where(x => x.Groups != null).SelectMany(x => x.Groups.ModifiedItems).Cast <TGroup>().ToList();

            modified = modified.Concat(Groups.ModifiedItems).ToList();

            Groups.AcceptChanges();

            added.Concat(modified.Select(x => x.Model)).Distinct().ForEach(x => eventAggregator.GetEvent <TAfterSaveEvent>().Publish(x));
        }