Beispiel #1
0
        public async Task <bool> SaveBranches(IDbConnection connection)
        {
            bool   retValue  = true;
            string deleteAll = string.Format("DELETE FROM ProDelega WHERE cldIdCliente='{0}'",
                                             this.Value.NUM_PROVEE);
            await connection.ExecuteAsync(deleteAll);

            IMapper tmpMapper = MapperField.GetMapper();

            foreach (var branch in this.BranchesDtos)
            {
                ProDelega delega = tmpMapper.Map <BranchesDto, ProDelega>(branch);
                delega.cldIdCliente = this.Value.NUM_PROVEE;

                try

                {
                    int value = await connection.InsertAsync(delega);
                }
                catch (System.Exception e)
                {
                    retValue = false;
                    string message = "Transaction Scope Exception in Vehicle Insertion. Reason: " + e.Message;
                    logger.Error(message);
                    DataLayerExecutionException dataLayer = new DataLayerExecutionException(message);
                    throw dataLayer;
                }
            }
            return(retValue);
        }
Beispiel #2
0
        public async Task <bool> SaveChanges()
        {
            FillCities(ref _supplierValue);

            PROVEE1 provee1 = _supplierMapper.Map <SupplierPoco, PROVEE1>(_supplierValue);
            PROVEE2 provee2 = _supplierMapper.Map <SupplierPoco, PROVEE2>(_supplierValue);

            bool retValue = false;

            try
            {
                // TODO: Reverse.
                using (IDbConnection connection = _sqlExecutor.OpenNewDbConnection())
                {
                    using (TransactionScope transactionScope =
                               new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                    {
                        string value = string.Format(TipoProveSelect, provee1.NUM_PROVEE);
                        IEnumerable <TIPOPROVE> prove = await connection.QueryAsync <TIPOPROVE>(value).ConfigureAwait(false);

                        var tipoProve = prove.FirstOrDefault <TIPOPROVE>();

                        // here we shall already have the correct change in the VehiclePoco. It shall already validated.
                        // now we have to add the new connection.
                        try
                        {
                            retValue = await connection.UpdateAsync(provee1).ConfigureAwait(false);

                            retValue = retValue && await connection.UpdateAsync(provee2).ConfigureAwait(false);

                            retValue = retValue && await SaveContacts(connection).ConfigureAwait(false);

                            retValue = await SaveBranches(connection).ConfigureAwait(false) && retValue;

                            transactionScope.Complete();
                        }
                        catch (TransactionException ex)
                        {
                            transactionScope.Dispose();
                            string message = "Transaction Scope Exception in Vehicle Update. Reason: " + ex.Message;
                            logger.Error(message);
                            DataLayerExecutionException dataLayer = new DataLayerExecutionException(message);
                            throw dataLayer;
                        }
                        catch (System.Exception other)
                        {
                            logger.Error(other);
                            return(retValue);
                        }
                    }
                }
            }

            catch (System.Exception e)
            {
                logger.Error(e);
            }

            return(retValue);
        }
Beispiel #3
0
        public async Task <bool> Save()
        {
            // set reference to city dto.
            FillCities(ref _supplierValue);

            PROVEE1 provee1 = _supplierMapper.Map <SupplierPoco, PROVEE1>(_supplierValue);
            PROVEE2 provee2 = _supplierMapper.Map <SupplierPoco, PROVEE2>(_supplierValue);

            provee1.NUM_PROVEE = provee2.NUM_PROVEE;
            logger.Debug("Saving supplier " + provee2.NUM_PROVEE);

            bool retValue = false;

            using (IDbConnection connection = _sqlExecutor.OpenNewDbConnection())
            {
                using (TransactionScope transactionScope =
                           new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    try
                    {
                        int ret = await connection.InsertAsync(provee1);

                        retValue = ret == 0;
                        ret      = await connection.InsertAsync(provee2);

                        retValue = retValue && await SaveBranches(connection);

                        retValue = retValue && await SaveContacts(connection);

                        transactionScope.Complete();
                        retValue = retValue && (ret == 0);
                    }
                    catch (TransactionException ex)
                    {
                        string message = "Transaction Scope Exception in Supplier Insertion. Reason: " + ex.Message;
                        DataLayerExecutionException dataLayer = new DataLayerExecutionException(message);
                        logger.Error(ex, "Exception while saving a supplier. Transaction Scope saving.");
                        throw dataLayer;
                    }
                    catch (System.Exception other)
                    {
                        string message = "Error in a Supplier. Reason: " + other.Message;
                        logger.Error(other, "Exception while saving a supplier..");
                        DataLayerExecutionException dataLayer = new DataLayerExecutionException(message);
                        throw dataLayer;
                    }
                }
            }
            return(retValue);
        }
Beispiel #4
0
        /// <summary>
        ///  This method save the vehicle. Throws a DataLayerExecution exception in case the tr
        /// </summary>
        /// <returns>Returns true if we have saved the changes.</returns>
        public async Task <bool> SaveChanges()
        {
            VEHICULO1 vehiculo1 = _vehicleMapper.Map <VehiclePoco, VEHICULO1>(_vehicleValue);
            VEHICULO2 vehiculo2 = _vehicleMapper.Map <VehiclePoco, VEHICULO2>(_vehicleValue);
            bool      retValue  = false;

            try
            {
                // TODO: Reverse.
                using (IDbConnection connection = _sqlExecutor.OpenNewDbConnection())
                {
                    using (TransactionScope transactionScope =
                               new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                    {
                        // here we shall already have the correct change in the VehiclePoco. It shall already validated.
                        // now we have to add the new connection.
                        try
                        {
                            retValue = await connection.UpdateAsync(vehiculo1);

                            retValue = retValue && await connection.UpdateAsync(vehiculo2);

                            transactionScope.Complete();
                        }
                        catch (TransactionException ex)
                        {
                            string message = "Transaction Scope Exception in Vehicle Update. Reason: " + ex.Message;
                            DataLayerExecutionException dataLayer = new DataLayerExecutionException(message);
                            throw dataLayer;
                        }
                        catch (System.Exception other)
                        {
                            string message = "Save Exception in Vehicle Update. Reason: " + other.Message;
                            DataLayerExecutionException dataLayer = new DataLayerExecutionException(message, other);
                            throw dataLayer;
                        }
                    }
                }
            }
            catch (System.Exception other2)
            {
                string message = "Connection Exception in Vehicle Update. Reason: " + other2.Message;
                DataLayerExecutionException dataLayer = new DataLayerExecutionException(message, other2);
                throw dataLayer;
            }
            return(retValue);
        }
Beispiel #5
0
        /// <summary>
        ///  Save asynchronous data
        /// </summary>
        /// <returns></returns>
        public async Task <bool> Save()
        {
            var vehicleDto = Value;

            _vehicleValue = _vehicleMapper.Map <VehicleDto, VehiclePoco>(vehicleDto);
            VEHICULO1 vehiculo1 = _vehicleMapper.Map <VehiclePoco, VEHICULO1>(_vehicleValue);
            VEHICULO2 vehiculo2 = _vehicleMapper.Map <VehiclePoco, VEHICULO2>(_vehicleValue);

            vehiculo2.CODIINT = vehiculo1.CODIINT;
            Contract.Requires(vehiculo1.CODIINT != null, "Null PrimaryKey before Saving");
            Contract.Requires(vehiculo2.CODIINT != null, "Null PrimaryKey before Saving");
            bool retValue = false;

            using (IDbConnection connection = _sqlExecutor.OpenNewDbConnection())
            {
                using (TransactionScope transactionScope =
                           new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    try
                    {
                        int ret = await connection.InsertAsync(vehiculo1);

                        retValue = ret > 0;
                        ret      = await connection.InsertAsync(vehiculo2);

                        transactionScope.Complete();
                        retValue = retValue && (ret > 0);
                    }
                    catch (TransactionException ex)
                    {
                        // this is  an antipattern for exception handling.
                        string message = "Transaction Scope Exception in Vehicle Insertion. Reason: " + ex.Message;
                        _logger.Log(LogLevel.Error, message);
                        DataLayerExecutionException dataLayer = new DataLayerExecutionException(message);
                        throw dataLayer;
                    }
                    catch (System.Exception other)
                    {
                        string message = "Error in a Vehicle Insertion. Reason: " + other.Message;
                        _logger.Log(LogLevel.Error, message);
                        DataLayerExecutionException dataLayer = new DataLayerExecutionException(message);
                        throw dataLayer;
                    }
                }
            }
            return(retValue);
        }
Beispiel #6
0
        /// <summary>
        ///  Save the contacts.
        /// </summary>
        /// <param name="connection">Connection</param>
        /// <returns></returns>
        public async Task <bool> SaveContacts(IDbConnection connection)
        {
            bool   retValue  = true;
            string deleteAll = string.Format("DELETE FROM ProContactos WHERE ccoIdCliente='{0}'",
                                             this.Value.NUM_PROVEE);
            await connection.ExecuteAsync(deleteAll);

            foreach (var c in this.ContactsDtos)
            {
                ProContactos cont = new ProContactos();
                cont.ccoCargo      = c.Responsability;
                cont.ULTMODI       = c.LastMod;
                cont.ccoIdContacto = c.ContactId.ToString();
                cont.ccoIdCliente  = this.Value.NUM_PROVEE;
                cont.ccoContacto   = c.ContactName;
                cont.ccoIdDelega   = c.CurrentDelegation;
                cont.ccoTelefono   = c.Telefono;
                cont.ccoFax        = c.Fax;
                cont.ccoMail       = c.Email;
                cont.ccoMovil      = c.Movil;
                DateTime time = DateTime.Now;
                cont.ULTMODI = time.ToString("yyyMMddHHmmss");
                cont.USUARIO = c.User;

                try

                {
                    await connection.InsertAsync(cont);
                }
                catch (System.Exception e)
                {
                    string message = "Transaction Scope Exception in Vehicle Insertion. Reason: " + e.Message;
                    logger.Error(message);

                    DataLayerExecutionException dataLayer = new DataLayerExecutionException(message);
                    throw dataLayer;
                }
            }
            return(retValue);
        }