Exemple #1
0
        public IList <Contrato> ObtenerPorFecha(BusquedaFecha fecha)
        {
            IList <Contrato> res = new List <Contrato>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = "SELECT  IdContrato, FechaAlta, FechaBaja, c.IdGarante, c.IdInquilino, c.IdInmueble ," +
                             " g.Nombre, g.Apellido , i.Nombre,i.Apellido, ii.Precio " +
                             " FROM Contratos c INNER JOIN Garantes g ON c.IdGarante = g.IdGarante " +

                             "INNER JOIN Inquilinos i ON c.IdInquilino = i.IdInquilino " +
                             "INNER JOIN Inmuebles ii ON c.IdInmueble = ii.IdInmueble " +
                             $"WHERE c.FechaAlta BETWEEN @fechaAlta AND @fechaAlta OR c.FechaBaja BETWEEN @fechaAlta AND @fechaBaja";           // debo mostrar tambien los contratos vigentes
                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())
                    {
                        Contrato entidad = new Contrato
                        {
                            IdContrato = reader.GetInt32(0),
                            FechaAlta  = reader.GetDateTime(1),
                            FechaBaja  = reader.GetDateTime(2),
                            IdGarante  = reader.GetInt32(3),
                            garante    = new Garante
                            {
                                //IdPropietario = reader.GetInt32(8),
                                Nombre   = reader.GetString(6),
                                Apellido = reader.GetString(7),
                            },
                            IdInquilino = reader.GetInt32(4),
                            inquilino   = new Inquilino
                            {
                                //IdPropietario = reader.GetInt32(8),
                                Nombre   = reader.GetString(8),
                                Apellido = reader.GetString(9),
                            },

                            IdInmueble = reader.GetInt32(5),
                            inmueble   = new Inmueble
                            {
                                //IdPropietario = reader.GetInt32(8),
                                Precio = reader.GetDecimal(10)
                            }
                        };       //termina entidad
                        res.Add(entidad);
                    }            //termina whilw
                    connection.Close();
                }                //termina using
            }

            return(res);
        }
Exemple #2
0
        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);
        }