示例#1
0
        public List <Pago> ObtenerTodos(int id)
        {
            List <Pago> res = new List <Pago>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"SELECT pago.id, FechaPago, pago.Precio, ContratoId, contrato.InmuebleId, inmueble.Precio " +
                             $"FROM Pagos pago " +
                             $"INNER JOIN Contratos contrato ON pago.ContratoId = contrato.id " +
                             $"INNER JOIN Inmuebles inmueble ON contrato.InmuebleId = inmueble.id " +
                             $"WHERE contrato.id = @id AND pago.Estado = 1;";

                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.Parameters.AddWithValue("@id", id);
                    command.CommandType = CommandType.Text;
                    connection.Open();
                    var reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        Pago pago = new Pago
                        {
                            Id         = reader.GetInt32(0),
                            FechaPago  = reader.GetDateTime(1),
                            Precio     = reader.GetDecimal(2),
                            ContratoId = reader.GetInt32(3),
                            Contrato   = new Contrato
                            {
                                Id         = reader.GetInt32(3),
                                InmuebleId = reader.GetInt32(4),
                                Inmueble   = new Inmueble
                                {
                                    Id     = reader.GetInt32(4),
                                    Precio = reader.GetDecimal(5),
                                }
                            }
                        };
                        res.Add(pago);
                    }
                    connection.Close();
                }
            }
            return(res);
        }
示例#2
0
        public int Modificacion(Pago pago)
        {
            int res = -1;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"UPDATE Pagos SET FechaPago = @FechaPago, ContratoId = @ContratoId " +
                             $"WHERE id = @id";

                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = CommandType.Text;
                    command.Parameters.AddWithValue("@id", pago.Id);
                    command.Parameters.AddWithValue("@FechaPago", pago.FechaPago);
                    command.Parameters.AddWithValue("@ContratoId", pago.ContratoId);

                    connection.Open();
                    res = command.ExecuteNonQuery();
                    connection.Close();
                }
            }
            return(res);
        }