System.Transactions.TransactionScope.Complete C# (CSharp) Method

Complete() public method

public Complete ( ) : void
return void
        public void Complete()
        {
            TransactionsEtwProvider etwLog = TransactionsEtwProvider.Log;
            if (etwLog.IsEnabled())
            {
                etwLog.MethodEnter(TraceSourceType.TraceSourceBase, this);
            }
            if (_disposed)
            {
                throw new ObjectDisposedException(nameof(TransactionScope));
            }

            if (_complete)
            {
                throw TransactionException.CreateInvalidOperationException(TraceSourceType.TraceSourceBase, SR.DisposeScope, null);
            }

            _complete = true;
            if (etwLog.IsEnabled())
            {
                etwLog.MethodExit(TraceSourceType.TraceSourceBase, this);
            }
        }

Usage Example

        public void GuardarAsignaciones(IList<int> ordenesVenta, IList<Usuario> asistentes)
        {
            try
            {
                var transactionOptions = new TransactionOptions { IsolationLevel = IsolationLevel.ReadUncommitted };

                using (var transactionScope = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
                {
                    foreach (var idOrdenVenta in ordenesVenta)
                    {
                        var ordenVenta = _orderVentaDA.ObtenerPorID(idOrdenVenta);

                        var asistenteConMenorCarga = asistentes.OrderBy(p => p.CantidadOV).FirstOrDefault();

                        if (asistenteConMenorCarga != null)
                        {
                            asistenteConMenorCarga.CantidadOV++;

                            ordenVenta.Estado = Constantes.EstadoOrdenVenta.Asignado;
                            ordenVenta.AsistentePlaneamiento = asistenteConMenorCarga;

                            _orderVentaDA.AsignarAsistentePlaneamiento(ordenVenta);
                        }
                    }

                    transactionScope.Complete();
                }
            }
            catch (Exception ex)
            {
                throw ThrowException(ex, MethodBase.GetCurrentMethod().Name);
            }
        }
All Usage Examples Of System.Transactions.TransactionScope::Complete