Exemplo n.º 1
0
        public int Modificacion(Inmueble i)
        {
            int res = -1;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"UPDATE Inmuebles SET Direccion='{i.Direccion}', UsoResidencial={i.UsoResidencial}, Tipo='{i.Tipo}', Ambientes={i.Ambientes}, Precio= {i.Precio}, " +
                             $"Disponibilidad={i.Disponibilidad}, " +
                             $" EstadoInmueble = 1, IdPropietario = {i.IdPropietario}, Latitud = {i.Latitud}, Longitud = {i.Longitud} WHERE IdInmueble = {i.IdInmueble} ;";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = CommandType.Text;
                    connection.Open();
                    res = command.ExecuteNonQuery();
                    connection.Close();
                }
            }
            return(res);
        }
Exemplo n.º 2
0
        public IList <Inmueble> ObtenerPorIdPropietario(int id)
        {
            IList <Inmueble> res = new List <Inmueble>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"SELECT IdInmueble, Direccion, UsoResidencial, Tipo, Ambientes, " +
                             $"Precio, Disponibilidad, EstadoInmueble, i.IdPropietario, Latitud, Longitud, p.Nombre, p.Apellido " +
                             $" FROM Inmuebles i INNER JOIN Propietarios p ON i.IdPropietario = p.IdPropietario WHERE i.IdPropietario=@id AND EstadoInmueble = 1;";
                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();
                    while (reader.Read())
                    {
                        Inmueble i = new Inmueble
                        {
                            IdInmueble     = reader.GetInt32(0),
                            Direccion      = reader.GetString(1),
                            UsoResidencial = reader.GetByte(2),
                            Tipo           = reader.GetString(3),
                            Ambientes      = reader.GetInt32(4),
                            Precio         = reader.GetDecimal(5),
                            Disponibilidad = reader.GetByte(6),
                            EstadoInmueble = reader.GetByte(7),
                            IdPropietario  = reader.GetInt32(8),
                            Latitud        = reader.GetDecimal(9),
                            Longitud       = reader.GetDecimal(10),
                            Duenio         = new Propietario
                            {
                                Nombre   = reader.GetString(11),
                                Apellido = reader.GetString(12),
                            }
                        };
                        res.Add(i);
                    }
                    connection.Close();
                }
            }
            return(res);
        }
Exemplo n.º 3
0
        public int Alta(Inmueble i)
        {
            int res = -1;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"INSERT INTO Inmuebles (Direccion, UsoResidencial, Tipo, Ambientes, Precio, Disponibilidad, " +
                             $"EstadoInmueble, IdPropietario, Latitud, Longitud) " +
                             $"VALUES ('{i.Direccion}', {i.UsoResidencial}, '{i.Tipo}', {i.Ambientes}, {i.Precio}, " +
                             $"{i.Disponibilidad}, 1 , {i.IdPropietario}, {i.Latitud} , {i.Longitud}) ;";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = CommandType.Text;
                    connection.Open();
                    res = command.ExecuteNonQuery();
                    command.CommandText = "SELECT SCOPE_IDENTITY()";
                    var id = command.ExecuteScalar();
                    i.IdInmueble = Convert.ToInt32(id);
                    connection.Close();
                }
            }
            return(res);
        }
Exemplo n.º 4
0
        public Inmueble ObtenerPorId(int id)
        {
            Inmueble i = null;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"SELECT IdInmueble, Direccion, UsoResidencial, Tipo, Ambientes, Precio, Disponibilidad, EstadoInmueble, IdPropietario, Latitud, Longitud " +
                             $" FROM Inmuebles WHERE IdInmueble=@id AND EstadoInmueble = 1;";
                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
                        {
                            IdInmueble     = reader.GetInt32(0),
                            Direccion      = reader.GetString(1),
                            UsoResidencial = reader.GetByte(2),
                            Tipo           = reader.GetString(3),
                            Ambientes      = reader.GetInt32(4),
                            Precio         = reader.GetDecimal(5),
                            Disponibilidad = reader.GetByte(6),
                            EstadoInmueble = reader.GetByte(7),
                            IdPropietario  = reader.GetInt32(8),
                            Latitud        = reader.GetDecimal(9),
                            Longitud       = reader.GetDecimal(10),
                        };
                    }
                    connection.Close();
                }
            }
            return(i);
        }
Exemplo n.º 5
0
        public IList <Inmueble> ObtenerDisponibles()
        {
            IList <Inmueble> res = new List <Inmueble>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"SELECT IdInmueble, Direccion, UsoResidencial, Tipo, Ambientes, Precio, Disponibilidad, EstadoInmueble, IdPropietario, Latitud, Longitud " +
                             $" FROM Inmuebles WHERE Disponibilidad = 1 AND EstadoInmueble = 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
                        {
                            IdInmueble     = reader.GetInt32(0),
                            Direccion      = reader.GetString(1),
                            UsoResidencial = reader.GetByte(2),
                            Tipo           = reader.GetString(3),
                            Ambientes      = reader.GetInt32(4),
                            Precio         = reader.GetDecimal(5),
                            Disponibilidad = reader.GetByte(6),
                            EstadoInmueble = reader.GetByte(7),
                            IdPropietario  = reader.GetInt32(8),
                            Latitud        = reader.GetDecimal(9),
                            Longitud       = reader.GetDecimal(10),
                        };
                        res.Add(i);
                    }
                    connection.Close();
                }
            }
            return(res);
        }