示例#1
0
        public IList <Inmueble> ObtenerTodosPorPropietarioId(int IdPropie)
        {
            IList <Inmueble> res = new List <Inmueble>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"SELECT i.IdInmueble, IdPropie, Direccion, Tipo, Precio, Estado " +
                             " p.Nombre, p.Apellido" +
                             " FROM Inmueble i INNER JOIN Propietario p ON i.IdPropie = p.IdPropietario" +
                             $" WHERE i.IdPropie = @IdPropietario";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.Parameters.Add("@idPropietario", SqlDbType.Int).Value = IdPropie;
                    command.CommandType = CommandType.Text;
                    connection.Open();
                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        Inmueble i = new Inmueble
                        {
                            IdInmueble  = reader.GetInt32(0),
                            IdPropie    = reader.GetInt32(1),
                            Propietario = new Propietario
                            {
                                IdPropietario = reader.GetInt32(1),
                                Nombre        = reader.GetString(2),
                                Apellido      = reader.GetString(3),
                            },
                            Direccion = reader.GetString(4),
                            Tipo      = reader.GetString(5),
                            Precio    = reader.GetDecimal(6),
                            Estado    = reader.GetBoolean(7),
                        };
                        res.Add(i);
                    }
                    connection.Close();
                }
            }
            return(res);
        }
示例#2
0
        public List <Inmueble> BuscarPorPropietario(int id)
        {
            List <Inmueble> res = new List <Inmueble>();
            Inmueble        inm = null;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"SELECT IdInmueble, IdPropie, Direccion, Tipo, Precio, Estado" +
                             $" FROM Inmuebles" +
                             $" WHERE IdPropie=@idPropietario AND Disponible = 1";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.Parameters.Add("@idPropietario", SqlDbType.Int).Value = id;
                    command.CommandType = CommandType.Text;
                    connection.Open();
                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        inm = new Inmueble
                        {
                            IdInmueble  = reader.GetInt32(0),
                            Propietario = new Propietario
                            {
                                IdPropietario = reader.GetInt32(1),
                                Nombre        = reader.GetString(2),
                                Apellido      = reader.GetString(3),
                            },
                            Direccion = reader.GetString(4),
                            Tipo      = reader.GetString(5),
                            Precio    = reader.GetDecimal(6),
                            Estado    = reader.GetBoolean(7),
                        };
                        res.Add(inm);
                    }
                    connection.Close();
                }
            }
            return(res);
        }
示例#3
0
        public Inmueble ObtenerPorId(int id)
        {
            Inmueble i = null;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"SELECT IdInmueble, IdPropie, Direccion, Tipo, Precio, Estado, p.Nombre, p.Apellido " +
                             $" FROM Inmueble i INNER JOIN Propietario p ON i.IdInmueble = p.IdPropietario" +
                             $" WHERE i.IdInmueble=@idInmueble";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.Parameters.Add("@idInmueble", SqlDbType.Int).Value = id;
                    command.CommandType = CommandType.Text;
                    connection.Open();
                    var reader = command.ExecuteReader();
                    if (reader.Read())
                    {
                        i = new Inmueble
                        {
                            IdInmueble = reader.GetInt32(0),
                            IdPropie   = reader.GetInt32(1),
                            Direccion  = reader.GetString(2),
                            Tipo       = reader.GetString(3),
                            Precio     = reader.GetDecimal(4),
                            Estado     = reader.GetBoolean(5),

                            Propietario = new Propietario
                            {
                                IdPropietario = reader.GetInt32(1),
                                Nombre        = reader.GetString(6),
                                Apellido      = reader.GetString(7),
                            }
                        };
                    }
                    connection.Close();
                }
            }
            return(i);
        }
示例#4
0
        public int Modificacion(Inmueble i)
        {
            int res = -1;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"UPDATE Inmueble SET IdPropie=@idPropietario, Direccion=@direccion, Tipo=@tipo, Precio=@precio, Estado=@estado " +
                             $"WHERE IdInmueble = @idInmueble ";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = CommandType.Text;
                    command.Parameters.AddWithValue("@IdPropietario", i.IdPropie);
                    command.Parameters.AddWithValue("@direccion", i.Direccion);
                    command.Parameters.AddWithValue("@tipo", i.Tipo);
                    command.Parameters.AddWithValue("@precio", i.Precio);
                    command.Parameters.AddWithValue("@estado", i.Estado);
                    command.Parameters.AddWithValue("@IdInmueble", i.IdInmueble);
                    connection.Open();
                    res = command.ExecuteNonQuery();
                    connection.Close();
                }
            }
            return(res);
        }