virtual public Inmueble ObtenerPorId(int id) { Inmueble e = null; using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"SELECT i.id,tipo,uso,direccion, cantAmbientes, precio,propietarioId,disponible, p.Nombre, p.Apellido" + $" FROM Inmuebles i INNER JOIN Propietarios p ON i.propietarioId = p.id" + $" WHERE i.id=@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()) { e = new Inmueble { Id = reader.GetInt32(0), Tipo = reader.GetString(1), Uso = reader.GetString(2), Direccion = reader.GetString(3), CantAmbientes = reader.GetInt32(4), Precio = reader.GetDecimal(5), PropietarioId = reader.GetInt32(6), Disponible = reader.GetInt32(7), PropietarioInmueble = new Propietario { Id = reader.GetInt32(6), Nombre = reader.GetString(8), Apellido = reader.GetString(9), } }; } connection.Close(); } return(e); } }
public IList <Inmueble> ObtenerLibresPorFecha(BusquedaFecha fecha) { IList <Inmueble> res = new List <Inmueble>(); using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = "SELECT i.IdInmueble, Direccion, TipoInmueble, Precio, CantHambientes, Uso, Estado, i.IdPropietario," + " p.Nombre, p.Apellido" + " FROM Inmuebles i INNER JOIN Propietarios p ON i.IdPropietario = p.IdPropietario" + " INNER JOIN Contratos c ON i.IdInmueble = c.IdInmueble" + $" WHERE i.Estado LIKE 'Disponible'AND i.IdInmueble NOT IN (SELECT c.IdInmueble FROM Contratos c WHERE c.FechaAlta BETWEEN @fechaAlta AND @fechaAlta OR c.FechaBaja BETWEEN @fechaAlta AND @fechaBaja)"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.Parameters.AddWithValue("@fechaAlta", fecha.FechaAlta); command.Parameters.AddWithValue("@fechaBaja", fecha.FechaBaja); command.CommandType = CommandType.Text; connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { Inmueble entidad = new Inmueble { IdInmueble = reader.GetInt32(0), Direccion = reader.GetString(1), TipoInmueble = reader.GetString(2), Precio = reader.GetDecimal(3), CantHambientes = reader.GetInt32(4), Uso = reader.GetString(5), Estado = reader.GetString(6), IdPropietario = reader.GetInt32(7), Propietario = new Propietario { Nombre = reader.GetString(8), Apellido = reader.GetString(9), } }; res.Add(entidad); } connection.Close(); } } return(res); }
public IList <Inmueble> BuscarPorPropietario(int idPropietario) { List <Inmueble> res = new List <Inmueble>(); Inmueble entidad = null; using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"SELECT i.Id, i.Direccion,Ambientes, Uso, Tipo, Precio, Estado, PropietarioId, p.Nombre, p.Apellido" + $" FROM Inmueble i INNER JOIN Propietario p ON i.PropietarioId = p.Id" + $" WHERE PropietarioId=@idPropietario"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.Parameters.Add("@idPropietario", SqlDbType.Int).Value = idPropietario; command.CommandType = CommandType.Text; connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { entidad = new Inmueble { Id = reader.GetInt32(0), Direccion = reader.GetString(1), Ambientes = reader.GetInt32(2), Uso = reader.GetInt32(3), Tipo = reader.GetInt32(4), Precio = reader.GetDecimal(5), Estado = reader.GetBoolean(6), PropietarioId = reader.GetInt32(7), Duenio = new Propietario { Id = reader.GetInt32(7), Nombre = reader.GetString(8), Apellido = reader.GetString(9), } }; res.Add(entidad); } connection.Close(); } } return(res); }
public List <Inmueble> ObtenerDisponible() { List <Inmueble> inmueble = new List <Inmueble>(); using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"SELECT i.Id,tipo,uso,direccion,cantAmbientes,precio,PropietarioId,disponible, p.nombre,p.apellido,p.dni,p.tel" + $" FROM Inmuebles i INNER JOIN Propietarios p ON i.PropietarioId = p.id" + $" WHERE disponibilidad= {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 { Id = reader.GetInt32(0), Tipo = reader.GetString(1), Uso = reader.GetString(2), Direccion = reader.GetString(3), CantAmbientes = reader.GetInt32(4), Precio = reader.GetDecimal(5), PropietarioId = reader.GetInt32(6), Disponible = reader.GetInt32(7), PropietarioInmueble = new Propietario { Id = reader.GetInt32(6), Nombre = reader.GetString(8), Apellido = reader.GetString(9), Dni = reader.GetString(10), Tel = reader.GetString(11), } }; inmueble.Add(i); } connection.Close(); } } return(inmueble); }
public List <Inmueble> inmueblesPorPropietario(int id) { var res = new List <Inmueble>(); using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = "SELECT i.Id,tipo,uso,direccion,cantAmbientes,precio,PropietarioId,disponible, p.nombre,p.apellido,p.dni,p.tel FROM Inmuebles i, Propietarios p WHERE i.PropietarioId = p.Id and (p.Id=@id)"; using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); command.Parameters.Add("@id", SqlDbType.Int).Value = id; var reader = command.ExecuteReader(); while (reader.Read()) { Inmueble e = new Inmueble { Id = reader.GetInt32(0), Tipo = reader.GetString(1), Uso = reader.GetString(2), Direccion = reader.GetString(3), CantAmbientes = reader.GetInt32(4), Precio = reader.GetDecimal(5), PropietarioId = reader.GetInt32(6), Disponible = reader.GetInt32(7), PropietarioInmueble = new Propietario { Id = reader.GetInt32(6), Nombre = reader.GetString(8), Apellido = reader.GetString(9), Dni = reader.GetString(10), Tel = reader.GetString(11), } }; res.Add(e); } connection.Close(); } return(res); } }
public IList <Inmueble> BuscarPorPropietario(string dni) { List <Inmueble> res = new List <Inmueble>(); Inmueble entidad = null; using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"SELECT IdInmueble, Direccion, TipoInmueble, Precio, CantHambientes, Uso, Estado, i.IdPropietario, p.Nombre, p.Apellido" + $" FROM Inmuebles i INNER JOIN Propietarios p ON i.IdPropietario = p.IdPropietario" + $" WHERE p.Dni=@dni"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.Parameters.AddWithValue("@dni", dni); command.CommandType = CommandType.Text; connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { entidad = new Inmueble { IdInmueble = reader.GetInt32(0), Direccion = reader.GetString(1), TipoInmueble = reader.GetString(2), Precio = reader.GetDecimal(3), CantHambientes = reader.GetInt32(4), Uso = reader.GetString(5), Estado = reader.GetString(6), IdPropietario = reader.GetInt32(7), Propietario = new Propietario { //IdPropietario = reader.GetInt32(6), Nombre = reader.GetString(8), Apellido = reader.GetString(9), } }; res.Add(entidad); } connection.Close(); } } return(res); }
public int Modificacion(Inmueble inmueble) { int res = -1; using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"UPDATE Inmuebles SET Latitud='{inmueble.Latitud}', Longitud='{inmueble.Longitud}', Tipo='{inmueble.Tipo}', " + $"Uso='{inmueble.Uso}', Ambientes={inmueble.Ambientes}, Direccion='{inmueble.Direccion}', " + $"Precio = {inmueble.Precio.ToString().Replace(",", ".")}, Estado={Convert.ToInt32(inmueble.Estado)} " + $"WHERE Id = {inmueble.Id};"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.CommandType = CommandType.Text; connection.Open(); res = command.ExecuteNonQuery(); connection.Close(); } } return(res); }
public int Update(Inmueble i) { int res = -1; using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"UPDATE Inmueble SET InmuebleDomicilio='{i.InmuebleDomicilio}', InmuebleLatitud='{i.InmuebleLatitud}', " + $"InmuebleLongitud='{i.InmuebleLongitud}', InmueblePrecio='{i.InmueblePrecio}', InmuebleAmbientes='{i.InmuebleAmbientes}', " + $"InmuebleEstado='{i.InmuebleEstado}', IdInmuebleUso='{i.IdInmuebleUso}', IdInmuebleTipo='{i.IdInmuebleTipo}', IdUsuario='{i.IdUsuario}' " + $"WHERE IdInmueble = '{i.IdInmueble}' "; using (SqlCommand command = new SqlCommand(sql, connection)) { command.CommandType = CommandType.Text; connection.Open(); res = command.ExecuteNonQuery(); connection.Close(); } } return(res); }
public IList <Inmueble> BuscarDisponibles() { IList <Inmueble> res = new List <Inmueble>(); using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = "SELECT i.Id, i.Direccion, Ambientes, Uso, Tipo, Precio, Estado, PropietarioId," + " p.Nombre, p.Apellido" + " FROM Inmueble i INNER JOIN Propietario p ON i.PropietarioId = p.Id" + " WHERE Estado = 'true'"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.CommandType = CommandType.Text; connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { Inmueble entidad = new Inmueble { Id = reader.GetInt32(0), Direccion = reader.GetString(1), Ambientes = reader.GetInt32(2), Uso = reader.GetInt32(3), Tipo = reader.GetInt32(4), Precio = reader.GetDecimal(5), Estado = reader.GetBoolean(6), PropietarioId = reader.GetInt32(7), Duenio = new Propietario { Id = reader.GetInt32(7), Nombre = reader.GetString(8), Apellido = reader.GetString(9), } }; res.Add(entidad); } connection.Close(); } } return(res); }
public List <Inmueble> ObtenerTodos() { var res = new List <Inmueble>(); using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = "SELECT i.id, tipo, uso, direccion, cantAmbientes, precio, propietarioId, disponible," + " p.nombre,p.apellido FROM Inmuebles i, Propietarios p WHERE i.propietarioId = p.id";; using (SqlCommand command = new SqlCommand(sql, connection)) { //command.CommandType = CommandType.Text; connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { Inmueble e = new Inmueble { Id = reader.GetInt32(0), Tipo = reader.GetString(1), Uso = reader.GetString(2), Direccion = reader.GetString(3), CantAmbientes = reader.GetInt32(4), Precio = reader.GetDecimal(5), PropietarioId = reader.GetInt32(6), Disponible = reader.GetInt32(7), PropietarioInmueble = new Propietario { Id = reader.GetInt32(6), Nombre = reader.GetString(8), Apellido = reader.GetString(9), } }; res.Add(e); } connection.Close(); } return(res); } }
public IList <Inmueble> BuscarPorPropietario(int idPropietario) { List <Inmueble> res = new List <Inmueble>(); Inmueble entidad = null; using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"SELECT i.Id, Latitud, Longitud, Tipo, Uso, Ambientes, Direccion, Precio, Estado, Propietario, p.Nombre," + $" p.Apellido FROM Inmuebles i INNER JOIN Propietarios p ON i.Propietario = p.Id WHERE Propietario={idPropietario}"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.CommandType = CommandType.Text; connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { entidad = new Inmueble { Id = reader.GetInt32(0), Latitud = reader.GetString(1), Longitud = reader.GetString(2), Tipo = reader.GetString(3), Uso = reader.GetString(4), Ambientes = reader.GetInt32(5), Direccion = reader.GetString(6), Precio = reader.GetDecimal(7), Estado = reader.GetBoolean(8), Propietario = new Propietario { Id = reader.GetInt32(9), Nombre = reader.GetString(10), Apellido = reader.GetString(11), } }; res.Add(entidad); } connection.Close(); } } return(res); }
public int Alta(Inmueble entidad) { int res = -1; using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"INSERT INTO Inmuebles (Direccion, Ambientes, Superficie, Latitud, Longitud, PropietarioId) " + $"VALUES ('{entidad.Direccion}', '{entidad.Ambientes}','{entidad.Superficie}','{entidad.Latitud}','{entidad.Longitud}','{entidad.PropietarioId}')"; 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(); entidad.IdInmueble = Convert.ToInt32(id); connection.Close(); } } return(res); }
public Inmueble ObtenerPorId(int id) { Inmueble entidad = null; using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"SELECT IdInmueble, Direccion, TipoInmueble, Precio, CantHambientes, Uso, Estado, i.IdPropietario, p.Nombre, p.Apellido" + $" FROM Inmuebles i INNER JOIN Propietarios p ON i.IdPropietario = p.IdPropietario" + $" WHERE IdInmueble=@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()) { entidad = new Inmueble { IdInmueble = reader.GetInt32(0), Direccion = reader.GetString(1), TipoInmueble = reader.GetString(2), Precio = reader.GetDecimal(3), CantHambientes = reader.GetInt32(4), Uso = reader.GetString(5), Estado = reader.GetString(6), IdPropietario = reader.GetInt32(7), Propietario = new Propietario { //IdPropietario = reader.GetInt32(8), Nombre = reader.GetString(8), Apellido = reader.GetString(9), } }; } connection.Close(); } } return(entidad); }
public IList <Inmueble> ObtenerDisponibles() { IList <Inmueble> res = new List <Inmueble>(); using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = "SELECT IdInmueble, Direccion, TipoInmueble, Precio, CantHambientes, Uso, Estado, i.IdPropietario," + " p.Nombre, p.Apellido" + " FROM Inmuebles i INNER JOIN Propietarios p ON i.IdPropietario = p.IdPropietario" + $" WHERE i.Estado LIKE 'Disponible'"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.CommandType = CommandType.Text; connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { Inmueble entidad = new Inmueble { IdInmueble = reader.GetInt32(0), Direccion = reader.GetString(1), TipoInmueble = reader.GetString(2), Precio = reader.GetDecimal(3), CantHambientes = reader.GetInt32(4), Uso = reader.GetString(5), Estado = reader.GetString(6), IdPropietario = reader.GetInt32(7), Propietario = new Propietario { Nombre = reader.GetString(8), Apellido = reader.GetString(9), } }; res.Add(entidad); } connection.Close(); } } return(res); }
public IList <Inmueble> ObtenerTodos() { IList <Inmueble> res = new List <Inmueble>(); using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"SELECT IdInmueble, Direccion, Estado, TipoDeUso, TipoDeInmueble, CantDeAmbientes, Precio, p.IdPropietario, p.Nombre, p.Apellido" + $" FROM Inmuebles i INNER JOIN Propietarios p ON i.IdPropietario = p.IdPropietario"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.CommandType = CommandType.Text; connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { Inmueble entidad = new Inmueble { IdInmueble = reader.GetInt32(0), Direccion = reader.GetString(1), Estado = reader.GetString(2), TipoDeUso = reader.GetString(3), TipoDeInmueble = reader.GetString(4), CantDeAmbientes = reader.GetInt32(5), Precio = reader.GetInt32(6), IdPropietario = reader.GetInt32(7), Propietario = new Propietario { IdPropietario = reader.GetInt32(7), Nombre = reader.GetString(8), Apellido = reader.GetString(9), } }; res.Add(entidad); } connection.Close(); } } return(res); }
public int Alta(Inmueble entidad) { int res = -1; using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"INSERT INTO Inmuebles (Latitud, Longitud, Tipo, Uso, Ambientes, Direccion, Precio, Estado, FechaAlta, Propietario) " + $"VALUES ('{entidad.Latitud}', '{entidad.Longitud}', '{entidad.Tipo}', '{entidad.Uso}', {entidad.Ambientes}, " + $"'{entidad.Direccion}', {entidad.Precio.ToString().Replace(",", ".")}, 1, SYSDATETIME(), {entidad.Propietario.Id}); " + $"SELECT SCOPE_IDENTITY() AS [IdGenerado]"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.CommandType = CommandType.Text; connection.Open(); int idGenerado = Convert.ToInt32(command.ExecuteScalar()); entidad.Id = idGenerado; connection.Close(); } } return(res); }
public Inmueble ObtenerPorId(int id) { Inmueble entidad = null; using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"SELECT IdInmueble, Direccion, Ambientes, Superficie, Latitud, Longitud, PropietarioId, p.Nombre, p.Apellido" + $" FROM Inmuebles i INNER JOIN Propietarios p ON i.PropietarioId = p.IdPropietario" + $" WHERE IdInmueble=@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()) { entidad = new Inmueble { IdInmueble = reader.GetInt32(0), Direccion = reader.GetString(1), Ambientes = reader.GetInt32(2), Superficie = reader.GetInt32(3), Latitud = reader.GetDecimal(4), Longitud = reader.GetDecimal(5), PropietarioId = reader.GetInt32(6), Duenio = new Propietario { IdPropietario = reader.GetInt32(6), Nombre = reader.GetString(7), Apellido = reader.GetString(8), } }; } connection.Close(); } } return(entidad); }
public IList <Inmueble> ObtenerTodos() { IList <Inmueble> res = new List <Inmueble>(); using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"SELECT IdInmueble, Direccion, Ambientes, Superficie, Latitud, Longitud, PropietarioId, p.Nombre, p.Apellido" + $" FROM Inmuebles i INNER JOIN Propietarios p ON i.PropietarioId = p.IdPropietario"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.CommandType = CommandType.Text; connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { Inmueble entidad = new Inmueble { IdInmueble = reader.GetInt32(0), Direccion = reader.GetString(1), Ambientes = reader.GetInt32(2), Superficie = reader.GetInt32(3), Latitud = reader.GetDecimal(4), Longitud = reader.GetDecimal(5), PropietarioId = reader.GetInt32(6), Duenio = new Propietario { IdPropietario = reader.GetInt32(6), Nombre = reader.GetString(7), Apellido = reader.GetString(8), } }; res.Add(entidad); } connection.Close(); } } return(res); }
public int Create(Inmueble inmueble) { int res = -1; using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"INSERT INTO Inmueble (InmuebleDomicilio, InmuebleLatitud, InmuebleLongitud, InmueblePrecio," + $" InmuebleAmbientes, InmuebleEstado, IdInmuebleUso, IdInmuebleTipo, IdUsuario) " + $"VALUES ('{inmueble.InmuebleDomicilio}','{inmueble.InmuebleLatitud}','{inmueble.InmuebleLongitud}','{inmueble.InmueblePrecio}'," + $"'{inmueble.InmuebleAmbientes}','{inmueble.InmuebleEstado}','{inmueble.IdInmuebleUso}','{inmueble.IdInmuebleTipo}','{inmueble.IdUsuario}')"; 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(); inmueble.IdUsuario = Convert.ToInt32(id); connection.Close(); } } return(res); }
public int Agregar(Inmueble inmueble) { int res = -1; using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"INSERT INTO Inmuebles (tipo,uso,direccion, cantAmbientes, precio,propietarioId,disponible,imagen)" + "VALUES (@tipo,@uso,@direccion,@cantAmbientes, @precio, @propietarioId, @disponible,@imagen);" + "SELECT SCOPE_IDENTITY();"; using (var command = new SqlCommand(sql, connection)) { command.Parameters.AddWithValue("@tipo", inmueble.Tipo); command.Parameters.AddWithValue("@uso", inmueble.Uso); command.Parameters.AddWithValue("@direccion", inmueble.Direccion); command.Parameters.AddWithValue("@cantAmbientes", inmueble.CantAmbientes); command.Parameters.AddWithValue("@precio", inmueble.Precio); command.Parameters.AddWithValue("@propietarioId", inmueble.PropietarioId); command.Parameters.AddWithValue("@disponible", inmueble.Disponible); if (String.IsNullOrEmpty(inmueble.Imagen)) { command.Parameters.AddWithValue("@imagen", DBNull.Value); } else { command.Parameters.AddWithValue("@imagen", inmueble.Imagen); } connection.Open(); res = Convert.ToInt32(command.ExecuteScalar()); inmueble.Id = res; connection.Close(); } } return(res); }
public int Modificacion(Inmueble inmueble) { int res = -1; using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"UPDATE Inmuebles SET Direccion=@direccion, Ambientes=@ambientes, Superficie=@superficie, Latitud=@latitud, Longitud=@longitud, PropietarioId=@propietarioId " + $"WHERE IdInmueble = {inmueble.IdInmueble}"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.Parameters.Add("@direccion", SqlDbType.VarChar).Value = inmueble.Direccion; command.Parameters.Add("@ambientes", SqlDbType.Int).Value = inmueble.Ambientes; command.Parameters.Add("@superficie", SqlDbType.Int).Value = inmueble.Superficie; command.Parameters.Add("@latitud", SqlDbType.Decimal).Value = inmueble.Latitud; command.Parameters.Add("@longitud", SqlDbType.Decimal).Value = inmueble.Longitud; command.Parameters.Add("@propietarioId", SqlDbType.Int).Value = inmueble.PropietarioId; command.CommandType = CommandType.Text; connection.Open(); res = command.ExecuteNonQuery(); connection.Close(); } } return(res); }
public IList <Inmueble> GetByStatus(int status) { IList <Inmueble> res = new List <Inmueble>(); using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"SELECT i.IdInmueble, i.InmuebleDomicilio, i.InmuebleLatitud, " + $"i.InmuebleLongitud, i.InmueblePrecio, " + $"i.InmuebleAmbientes, i.InmuebleEstado, " + $"i.IdInmuebleUso, i.IdInmuebleTipo, i.IdUsuario, iu.InmuebleUsoNombre, it.InmuebleTipoNombre, u.UsuarioNombre, u.UsuarioDni " + $"FROM Inmueble i JOIN Usuario u ON u.IdUsuario = i.IdUsuario " + $" JOIN InmuebleTipo it ON it.IdInmuebleTipo = i.IdInmuebleTipo " + $" JOIN InmuebleUso iu ON iu.IdInmuebleUso = i.IdInmuebleUso " + $" WHERE u.IdUsuarioTipo = 3 and i.InmuebleEstado = {status} "; using (SqlCommand command = new SqlCommand(sql, connection)) { command.CommandType = CommandType.Text; connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { Inmueble entidad = new Inmueble { IdInmueble = reader.GetInt32(0), InmuebleDomicilio = reader.GetString(1), InmuebleLatitud = reader.GetDecimal(2), InmuebleLongitud = reader.GetDecimal(3), InmueblePrecio = reader.GetDecimal(4), InmuebleAmbientes = reader.GetInt32(5), InmuebleEstado = reader.GetByte(6), IdInmuebleUso = reader.GetInt32(7), IdInmuebleTipo = reader.GetInt32(8), IdUsuario = reader.GetInt32(9), InmuebleUso = new InmuebleUso { IdInmuebleUso = reader.GetInt32(7), InmuebleUsoNombre = reader.GetString(10), }, InmuebleTipo = new InmuebleTipo { IdInmuebleTipo = reader.GetInt32(8), InmuebleTipoNombre = reader.GetString(11), }, Usuario = new Usuario { IdUsuarioTipo = reader.GetInt32(9), UsuarioNombre = reader.GetString(12), UsuarioDni = reader.GetString(13), } }; res.Add(entidad); } connection.Close(); } } return(res); }
public IList <Inmueble> Buscar(Inmueble inmueble) { List <Inmueble> res = new List <Inmueble>(); Inmueble entidad = null; using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"SELECT i.Id, Latitud, Longitud, Tipo, Uso, Ambientes, Direccion, Precio, Estado, Propietario, p.Nombre," + $" p.Apellido FROM Inmuebles i INNER JOIN Propietarios p ON i.Propietario = p.Id "; if (inmueble.Tipo != "" || inmueble.Uso != "" || inmueble.Ambientes != 0 || inmueble.Precio != 0) { sql += "WHERE "; String strTipo = $" Tipo LIKE '%{inmueble.Tipo}%' "; String strUso = $" Uso LIKE '%{inmueble.Uso}%' "; String strAmbientes = $" Ambientes = {inmueble.Ambientes} "; String strPrecio = $" Precio BETWEEN {(inmueble.Precio - 2000).ToString().Replace(",", ".")} AND {(inmueble.Precio + 2000).ToString().Replace(",", ".")} "; List <String> partes = new List <String>(); if (inmueble.Tipo != "") { partes.Add(strTipo); } if (inmueble.Uso != "") { partes.Add(strUso); } if (inmueble.Ambientes != 0) { partes.Add(strAmbientes); } if (inmueble.Precio != 0) { partes.Add(strPrecio); } sql += String.Join("AND", partes); } using (SqlCommand command = new SqlCommand(sql, connection)) { command.CommandType = CommandType.Text; connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { entidad = new Inmueble { Id = reader.GetInt32(0), Latitud = reader.GetString(1), Longitud = reader.GetString(2), Tipo = reader.GetString(3), Uso = reader.GetString(4), Ambientes = reader.GetInt32(5), Direccion = reader.GetString(6), Precio = reader.GetDecimal(7), Estado = reader.GetBoolean(8), Propietario = new Propietario { Id = reader.GetInt32(9), Nombre = reader.GetString(10), Apellido = reader.GetString(11), } }; res.Add(entidad); } connection.Close(); } } return(res); }
public int Alta(Inmueble p) { throw new NotImplementedException(); }
public IList <Inmueble> GetByCriterio(BusquedaView busqueda) { if (busqueda.Tipo == 1) { busqueda.Campo = "u.UsuarioDni"; } else if (busqueda.Tipo == 2) { busqueda.Campo = "u.UsuarioNombre"; } else if (busqueda.Tipo == 3) { busqueda.Campo = "i.InmuebleAmbientes"; } else if (busqueda.Tipo == 4) { busqueda.Campo = "i.InmuebleEstado"; busqueda.Criterio = "0"; } else { busqueda.Campo = "i.InmuebleEstado"; busqueda.Criterio = "1"; } IList <Inmueble> res = new List <Inmueble>(); using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"SELECT i.IdInmueble, i.InmuebleDomicilio, i.InmuebleLatitud, " + $"i.InmuebleLongitud, i.InmueblePrecio, " + $"i.InmuebleAmbientes, i.InmuebleEstado, " + $"i.IdInmuebleUso, i.IdInmuebleTipo, i.IdUsuario, iu.InmuebleUsoNombre, it.InmuebleTipoNombre, u.UsuarioNombre, u.UsuarioDni " + $"FROM Inmueble i JOIN Usuario u ON u.IdUsuario = i.IdUsuario " + $" JOIN InmuebleTipo it ON it.IdInmuebleTipo = i.IdInmuebleTipo " + $" JOIN InmuebleUso iu ON iu.IdInmuebleUso = i.IdInmuebleUso " + $" WHERE u.IdUsuarioTipo = 3 and {busqueda.Campo} LIKE '%{busqueda.Criterio}%' "; using (SqlCommand command = new SqlCommand(sql, connection)) { command.CommandType = CommandType.Text; connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { Inmueble entidad = new Inmueble { IdInmueble = reader.GetInt32(0), InmuebleDomicilio = reader.GetString(1), InmuebleLatitud = reader.GetDecimal(2), InmuebleLongitud = reader.GetDecimal(3), InmueblePrecio = reader.GetDecimal(4), InmuebleAmbientes = reader.GetInt32(5), InmuebleEstado = reader.GetByte(6), IdInmuebleUso = reader.GetInt32(7), IdInmuebleTipo = reader.GetInt32(8), IdUsuario = reader.GetInt32(9), InmuebleUso = new InmuebleUso { IdInmuebleUso = reader.GetInt32(7), InmuebleUsoNombre = reader.GetString(10), }, InmuebleTipo = new InmuebleTipo { IdInmuebleTipo = reader.GetInt32(8), InmuebleTipoNombre = reader.GetString(11), }, Usuario = new Usuario { IdUsuarioTipo = reader.GetInt32(9), UsuarioNombre = reader.GetString(12), UsuarioDni = reader.GetString(13), } }; res.Add(entidad); } connection.Close(); } } return(res); }