Ejemplo n.º 1
0
        /// <summary>
        /// Accepts the changes.
        /// </summary>
        public virtual void AcceptChanges()
        {
            Logger.Debug(String.Format("Accepting changes with a following state {0}.", this.ObjectState.ToString()));
            using (TransactionScope scope = new TransactionScope())
            {
                switch (this.ObjectState)
                {
                case MetaObjectState.Added:
                    OnSaved(DataService.ExecuteNonExec(CreateInsertCommand()));
                    this._State = MetaObjectState.Unchanged;
                    break;

                case MetaObjectState.Modified:
                    OnSaved(DataService.ExecuteNonExec(CreateUpdateCommand()));
                    this._State = MetaObjectState.Unchanged;
                    break;

                case MetaObjectState.Deleted:
                    DataService.Run(CreateDeleteCommand());
                    // need to remove item from the collection
                    if (StorageCollection != null)
                    {
                        StorageCollection.RemovedDeletedItem(this);
                    }
                    break;

                case MetaObjectState.Unchanged:
                    break;
                }
                scope.Complete();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Accepts the changes.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="saveSystem">if set to <c>true</c> [save system].</param>
        internal void AcceptChanges(MetaDataContext context, bool saveSystem)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                if (saveSystem)
                {
                    switch (this.ObjectState)
                    {
                    case MetaObjectState.Added:
                        ProcessInsertUpdateResults(DataService.ExecuteNonExec(CreateInsertCommand(context)));
                        break;

                    case MetaObjectState.Modified:
                        ProcessInsertUpdateResults(DataService.ExecuteNonExec(CreateUpdateCommand(context)));
                        break;

                    case MetaObjectState.Deleted:
                        DataService.Run(CreateDeleteCommand(context));
                        // need to remove item from the collection
                        if (StorageCollection != null)
                        {
                            StorageCollection.RemovedDeletedItem(this);
                        }
                        break;

                    case MetaObjectState.Unchanged:
                        break;
                    }
                }

                base.AcceptChanges(context);
                scope.Complete();
            }
        }