public IEnumerable <Credito> GetAll()
 {
     using (IDbConnection connection = new SqlConnection(ConnectionRepository.GetConnectionString()))
     {
         connection.Open();
         var creditos = connection.Query <Credito>("sp_credito_listar", commandType: CommandType.StoredProcedure);
         return(creditos);
     }
 }
Exemple #2
0
 public IEnumerable <Cliente> GetClientes()
 {
     using (IDbConnection connection = new SqlConnection(ConnectionRepository.GetConnectionString()))
     {
         connection.Open();
         var clientes = connection.Query <Cliente>("sp_cliente_listar", commandType: CommandType.StoredProcedure);
         return(clientes);
     }
 }
        public Credito GetById(int id)
        {
            using (IDbConnection connection = new SqlConnection(ConnectionRepository.GetConnectionString()))
            {
                connection.Open();
                var parameters = new DynamicParameters();
                parameters.Add("IdCredito", id);

                var credito = connection.QuerySingle <Credito>("sp_credito_obtener", param: parameters, commandType: CommandType.StoredProcedure);
                return(credito);
            }
        }
        public bool Delete(int id)
        {
            using (IDbConnection connection = new SqlConnection(ConnectionRepository.GetConnectionString()))
            {
                connection.Open();
                var parameters = new DynamicParameters();
                parameters.Add("IdCredito", id);

                var result = connection.Execute("sp_credito_eliminar", param: parameters, commandType: CommandType.StoredProcedure);
                return(result > 0);
            }
        }
Exemple #5
0
        public Cliente GetCliente(string numeroDocumento)
        {
            using (IDbConnection connection = new SqlConnection(ConnectionRepository.GetConnectionString()))
            {
                connection.Open();
                var parameters = new DynamicParameters();
                parameters.Add("NumeroDocumento", numeroDocumento);

                var cliente = connection.QuerySingle <Cliente>("sp_cliente_obtener", param: parameters, commandType: CommandType.StoredProcedure);
                return(cliente);
            }
        }
        public Credito Update(Credito credito)
        {
            using (IDbConnection connection = new SqlConnection(ConnectionRepository.GetConnectionString()))
            {
                connection.Open();
                var parameters = new DynamicParameters();
                parameters.Add("IdCredito", credito.IdCredito);
                parameters.Add("TipoCredito", credito.TipoCredito);
                parameters.Add("IdCliente", credito.IdCliente);
                parameters.Add("Fecha", credito.Fecha);
                parameters.Add("Monto", credito.Monto);
                parameters.Add("DiaPago", credito.DiaPago);
                parameters.Add("Tasa", credito.Tasa);
                parameters.Add("Comision", credito.Comision);

                var result = connection.Execute("sp_credito_actualizar", param: parameters, commandType: CommandType.StoredProcedure);
                return(result > 0 ? credito : new Credito());
            }
        }
        public Credito Add(Credito credito)
        {
            using (IDbConnection connection = new SqlConnection(ConnectionRepository.GetConnectionString()))
            {
                connection.Open();
                var parameters = new DynamicParameters();
                parameters.Add("TipoCredito", credito.TipoCredito);
                parameters.Add("IdCliente", credito.IdCliente);
                parameters.Add("Fecha", credito.Fecha);
                parameters.Add("Monto", credito.Monto);
                parameters.Add("DiaPago", credito.DiaPago);
                parameters.Add("Tasa", credito.Tasa);
                parameters.Add("Comision", credito.Comision);
                parameters.Add("IdCredito", credito.IdCredito, DbType.Int32, ParameterDirection.Output);

                //va a obtener un valor autogenerado para IdCredito
                connection.ExecuteScalar("sp_credito_insertar", param: parameters, commandType: CommandType.StoredProcedure);
                var idCredito = parameters.Get <Int32>("IdCredito");
                credito.IdCredito = idCredito;
                return(credito);
            }
        }