コード例 #1
0
        public IList <Inmueble> ObtenerPorIdPropietario(int id)
        {
            IList <Inmueble> res = new List <Inmueble>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"SELECT id_Inmueble, i.id_Propietario, direccionInm, uso, tipo, cantAmbientes,precioInm,estadoInm," +
                             " p.nombreP,p.apellidoP" +
                             $" FROM Inmueble i INNER JOIN Propietario p ON i.id_Propietario = p.id_Propietario  " +
                             $" WHERE p.id_Propietario=@idP ";

                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = CommandType.Text;
                    command.Parameters.AddWithValue("@idP", id);
                    connection.Open();
                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        Inmueble i = new Inmueble
                        {
                            Id_Inmueble    = reader.GetInt32(0),
                            Id_Propietario = reader.GetInt32(1),
                            DireccionInm   = reader.GetString(2),
                            Uso            = reader.GetString(3),
                            Tipo           = reader.GetString(4),
                            CantAmbientes  = reader.GetInt32(5),
                            PrecioInm      = reader.GetDecimal(6),
                            EstadoInm      = reader.GetInt32(7),

                            Propietario = new Propietario
                            {
                                Id_Propietario = reader.GetInt32(1),
                                NombreP        = reader.GetString(8),
                                ApellidoP      = reader.GetString(9),
                            }
                        }; res.Add(i);
                    }

                    connection.Close();
                }
            }
            return(res);
        }
コード例 #2
0
        public IList <Inmueble> BuscarDisponibles(string uso, decimal costo)
        {
            List <Inmueble> res = new List <Inmueble>();
            Inmueble        p   = null;

            using (var connection = new MySqlConnection(connectionString))
            {
                string sql = $"SELECT i.Id, Direccion, Tipo, Uso, Ambientes, Costo, Disponible, PropietarioId, p.Nombre, p.Apellido " +
                             $" FROM Inmuebles i INNER JOIN Propietarios p ON i.PropietarioId = p.Id" +
                             $" WHERE Uso=@uso AND Costo<=@costo AND Disponible=true";
                using (var command = new MySqlCommand(sql, connection))
                {
                    command.Parameters.Add("@uso", MySqlDbType.String).Value    = uso;
                    command.Parameters.Add("@costo", MySqlDbType.Decimal).Value = costo;
                    command.CommandType = CommandType.Text;
                    connection.Open();
                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        p = new Inmueble
                        {
                            Id            = reader.GetInt32(0),
                            Direccion     = reader.GetString(1),
                            Tipo          = reader.GetInt32(2),
                            Uso           = reader.GetString(3),
                            Ambientes     = reader.GetInt32(4),
                            Costo         = reader.GetDecimal(5),
                            Disponible    = reader.GetBoolean(6),
                            PropietarioId = reader.GetInt32(7),
                            Duenio        = new Propietario
                            {
                                Id       = reader.GetInt32(7),
                                Nombre   = reader.GetString(8),
                                Apellido = reader.GetString(9),
                            }
                        };
                        res.Add(p);
                    }
                    connection.Close();
                }
            }
            return(res);
        }