Exemple #1
0
        public IList <Inmueble> ListarLosInmueblesQueDisponiblesConSuDuenio()
        {
            IList <Inmueble> res = new List <Inmueble>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"SELECT i.InmuebleId, Direccion, Ambientes, Tipo, Costo, Superficie, Latitud, Longitud, i.PropietarioId, " +
                             $" p.Nombre, p.Apellido, p.Telefono,p.Email,p.Dni " +
                             $" FROM Inmuebles i INNER JOIN Propietarios p ON i.PropietarioId = p.PropietarioId " +
                             $" WHERE i.EstaPublicado = 1";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = CommandType.Text;
                    connection.Open();
                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        Inmueble i = new Inmueble
                        {
                            InmuebleId    = reader.GetInt32(0),
                            Direccion     = reader.GetString(1),
                            Ambientes     = reader.GetInt32(2),
                            Tipo          = reader.GetString(3),
                            Costo         = reader.GetDecimal(4),
                            Superficie    = reader.GetDecimal(5),
                            Latitud       = reader.GetDecimal(6),
                            Longitud      = reader.GetDecimal(7),
                            PropietarioId = reader.GetInt32(8),
                            Propietario   = new Propietario
                            {
                                Nombre   = reader.GetString(9),
                                Apellido = reader.GetString(10),
                                Telefono = reader.GetString(11),
                                Email    = reader.GetString(12),
                                Dni      = reader.GetString(13),
                            }
                        };
                        res.Add(i);
                    }
                    connection.Close();
                }
            }
            return(res);
        }
Exemple #2
0
        public IList <Inmueble> ObtenerTodosLosDisponibles()
        {
            IList <Inmueble> res = new List <Inmueble>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"SELECT i.InmuebleId, Direccion, Ambientes, Tipo, Costo, Superficie, Latitud, Longitud, i.PropietarioId, " +
                             "p.Nombre,p.Apellido " +
                             " FROM Inmuebles i INNER JOIN Propietarios p ON i.PropietarioId = p.propietarioId " +
                             "WHERE i.EstaPublicado = 1" +
                             "ORDER BY Direccion ";
                using (var command = new SqlCommand(sql, connection))
                {
                    command.CommandType = CommandType.Text;
                    connection.Open();
                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        Inmueble i = new Inmueble
                        {
                            InmuebleId    = reader.GetInt32(0),
                            Direccion     = reader.GetString(1),
                            Ambientes     = reader.GetInt32(2),
                            Tipo          = reader.GetString(3),
                            Costo         = reader.GetDecimal(4),
                            Superficie    = reader.GetDecimal(5),
                            Latitud       = reader.GetDecimal(6),
                            Longitud      = reader.GetDecimal(7),
                            PropietarioId = reader.GetInt32(8),
                            Propietario   = new Propietario
                            {
                                Nombre   = reader.GetString(9),
                                Apellido = reader.GetString(10),
                            },
                        };
                        res.Add(i);
                    }
                    connection.Close();
                }
            }
            return(res);
        }
Exemple #3
0
        public Inmueble ObtenerPorId(int id)
        {
            Inmueble i = null;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"SELECT InmuebleId, Direccion, Ambientes, Tipo, Costo, Superficie, Latitud, Longitud, i.PropietarioId, " +
                             "p.Nombre,p.Apellido " +
                             "FROM Inmuebles i INNER JOIN Propietarios p ON i.PropietarioId = p.propietarioId " +
                             " WHERE i.InmuebleId=@id";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.Parameters.Add("@id", SqlDbType.Int).Value = id;
                    command.CommandType = CommandType.Text;
                    connection.Open();
                    var reader = command.ExecuteReader();
                    if (reader.Read())
                    {
                        i = new Inmueble
                        {
                            InmuebleId    = reader.GetInt32(0),
                            Direccion     = reader.GetString(1),
                            Ambientes     = reader.GetInt32(2),
                            Tipo          = reader.GetString(3),
                            Costo         = reader.GetDecimal(4),
                            Superficie    = reader.GetDecimal(5),
                            Latitud       = reader.GetDecimal(6),
                            Longitud      = reader.GetDecimal(7),
                            PropietarioId = reader.GetInt32(8),
                            Propietario   = new Propietario
                            {
                                Nombre   = reader.GetString(9),
                                Apellido = reader.GetString(10),
                            }
                        };
                    }
                    connection.Close();
                }
            }
            return(i);
        }