Example #1
0
        public DataTable ListaUncliente(int nit)
        {
            DataTable tabla = new DataTable();

            tabla = CLIENTES2.BuscarClientess(nit);
            return(tabla);
        }
Example #2
0
        /// <summary>
        ///  This delete asynchronous data
        /// </summary>
        /// <param name="data">Client data object</param>
        /// <returns></returns>
        public async Task <bool> DeleteAsync(ClientDto data)
        {
            Contract.Assert(data != null, "Invalid data transfer object");
            //var currentPoco = _mapper.Map<ClientDto, ClientPoco>(data);
            //  var code = currentPoco;
            CLIENTES1 client1 = new CLIENTES1();
            CLIENTES2 client2 = new CLIENTES2();

            client1.NUMERO_CLI = data.NUMERO_CLI;
            client2.NUMERO_CLI = data.NUMERO_CLI;

//            CLIENTES1 client1 = _mapper.Map<ClientPoco, CLIENTES1>(currentPoco);
//           CLIENTES2 client2 = _mapper.Map<ClientPoco, CLIENTES2>(currentPoco);
            bool retValue = false;

            if ((client1 == null) || (client2 == null))
            {
                return(false);
            }
            using (IDbConnection connection = _executor.OpenNewDbConnection())
            {
                try
                {
                    using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                    {
                        retValue = await connection.DeleteAsync <CLIENTES1>(client1).ConfigureAwait(false);

                        if (retValue)
                        {
                            retValue = await connection.DeleteAsync <CLIENTES2>(client2).ConfigureAwait(false);
                        }
                        await DeleteReferredTables(connection, data);

                        scope.Complete();
                    }
                }
                finally
                {
                    connection.Close();
                }
            }
            return(retValue);
        }
Example #3
0
        /// <summary>
        ///  Save the asynchronous client
        /// </summary>
        /// <param name="save">Data transfer to be saved</param>
        /// <returns>It returns the boolean value.</returns>
        public async Task <bool> SaveAsync(ClientDto save)
        {
            IDbConnection connection = null;

            ///ClientPoco currentPoco;
            if (ValidationChain != null)
            {
                if (!ValidationChain.Validate(save))
                {
                    throw new DataLayerInvalidClientException(ValidationChain.Errors);
                }
            }
            // currentPoco = _mapper.Map<ClientDto, ClientPoco>(save);
            //Contract.Assert(currentPoco != null, "Invalid Poco");
            CLIENTES1 client1  = _mapper.Map <ClientDto, CLIENTES1>(save);
            CLIENTES2 client2  = _mapper.Map <ClientDto, CLIENTES2>(save);
            bool      retValue = false;

            if ((client1 == null) || (client2 == null))
            {
                return(false);
            }

            using (connection = _executor.OpenNewDbConnection())
            {
                try
                {
                    using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                    {
                        var present = connection.IsPresent <CLIENTES1>(client1);

                        if (!present)
                        {
                            retValue = await connection.InsertAsync <CLIENTES1>(client1) > 0;

                            if (retValue)
                            {
                                retValue = await connection.InsertAsync <CLIENTES2>(client2) > 0;
                            }
                        }
                        else
                        {
                            retValue = await connection.UpdateAsync <CLIENTES1>(client1);

                            if (retValue)
                            {
                                retValue = await connection.UpdateAsync <CLIENTES2>(client2);
                            }
                        }
                        retValue = retValue && await SaveBranchesAsync(connection, save.BranchesDto);

                        retValue = retValue && await SaveContactsAsync(connection, save.ContactsDto);

                        retValue = retValue && await SaveVisitsAsync(connection, save.VisitsDto);

                        scope.Complete();
                    }
                }
                finally
                {
                    connection.Close();
                }
            }
            Contract.Ensures(connection.State == ConnectionState.Closed);
            return(retValue);
        }
Example #4
0
        /// <summary>
        ///  Save the asynchronous client
        /// </summary>
        /// <param name="save">Data transfer to be saved</param>
        /// <returns>It returns the boolean value.</returns>
        public async Task <bool> SaveAsync(ClientDto save)
        {
            IDbConnection connection = null;

            ///ClientPoco currentPoco;
            if (ValidationChain != null)
            {
                if (!ValidationChain.Validate(save))
                {
                    throw new DataLayerValidationException(ValidationChain.Errors);
                }
            }

            CLIENTES1 client1 = _mapper.Map <ClientDto, CLIENTES1>(save);

            if (!string.IsNullOrEmpty(save.CreditCardExpiryMonth) && !string.IsNullOrEmpty(save.CreditCardExpiryYear))
            {
                client1.TARCADU = string.Format("{0}/{1}", save.CreditCardExpiryMonth, save.CreditCardExpiryYear);
            }
            CLIENTES2 client2  = _mapper.Map <ClientDto, CLIENTES2>(save);
            var       retValue = false;

            if ((client1 == null) || (client2 == null))
            {
                return(false);
            }

            using (connection = _executor.OpenNewDbConnection())
            {
                try
                {
                    using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                    {
                        var present = connection.IsPresent <CLIENTES1>(client1);

                        if (!present)
                        {
                            retValue = await connection.InsertAsync <CLIENTES1>(client1).ConfigureAwait(false) > 0;

                            if (retValue)
                            {
                                retValue = await connection.InsertAsync <CLIENTES2>(client2).ConfigureAwait(false) > 0;
                            }
                        }
                        else
                        {
                            retValue = await connection.UpdateAsync <CLIENTES1>(client1).ConfigureAwait(false);

                            if (retValue)
                            {
                                retValue = await connection.UpdateAsync <CLIENTES2>(client2).ConfigureAwait(false);

                                /* there is a case of lack of cohoerence, due to the split between databases,
                                 * in case of a bad importation*/
                                if (!retValue)
                                {
                                    retValue = await connection.InsertAsync <CLIENTES2>(client2).ConfigureAwait(false) > 0;
                                }
                            }
                        }
                        retValue = retValue && await SaveBranchesAsync(connection, save.BranchesDto).ConfigureAwait(false);

                        retValue = retValue && await SaveContactsAsync(connection, save.ContactsDto).ConfigureAwait(false);

                        retValue = retValue && await SaveVisitsAsync(connection, save.VisitsDto).ConfigureAwait(false);

                        scope.Complete();
                    }
                }
                finally
                {
                    connection.Close();
                }
            }
            Contract.Ensures(connection.State == ConnectionState.Closed);
            return(retValue);
        }