コード例 #1
0
        public int Modificacion(Inmueble p)
        {
            int res = -1;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"UPDATE Inmuebles SET Direccion='{p.Direccion}', Ambientes='{p.Ambientes}', Superficie='{p.Superficie}', Latitud='{p.Latitud}', Longitud='{p.Longitud}', PropietarioId='1' , EstaPublicado='{p.EstaPublicado}', EstaHabilitado='{p.EstaHabilitado}'" +
                             $" WHERE inmuebleId = {p.inmuebleId}";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = CommandType.Text;
                    connection.Open();
                    res = command.ExecuteNonQuery();
                    connection.Close();
                }
            }
            return(res);
        }
コード例 #2
0
        public int Alta(Inmueble p)
        {
            int res = -1;

            using (SqlConnection connection = new SqlConnection(connectionString)) {
                string sql = $"INSERT INTO Inmuebles (Propietario,Direccion,Disponible,Ambientes,Precio,Categoria,Uso,Transaccion) " +
                             $"VALUES ('{p.IdPropietario}','{p.Direccion}',1,'{p.Ambientes}','{p.Precio}','{p.Categoria}','{p.Uso}','{p.Transaccion}')";
                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();
                    p.Id = Convert.ToInt32(id);
                    connection.Close();
                }
            }
            return(res);
        }
コード例 #3
0
        public IList <Inmueble> BuscarPorPropietario(int idPropietario)
        {
            List <Inmueble> res     = new List <Inmueble>();
            Inmueble        entidad = null;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"SELECT Id, Direccion, Ambientes, Precio, Tipo, Uso, Disponible, PropietarioId, p.Nombre, p.Apellido" +
                             $" FROM Inmuebles i INNER JOIN Propietarios p ON i.PropietarioId = p.IdPropietario" +
                             $" 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),
                            Precio        = reader.GetDecimal(3),
                            Tipo          = reader.GetString(4),
                            Uso           = reader.GetString(5),
                            Disponible    = reader.GetInt32(6),
                            PropietarioId = reader.GetInt32(7),
                            Duenio        = new Propietario
                            {
                                IdPropietario = reader.GetInt32(7),
                                Nombre        = reader.GetString(8),
                                Apellido      = reader.GetString(9),
                            }
                        };
                        res.Add(entidad);
                    }
                    connection.Close();
                }
            }
            return(res);
        }
コード例 #4
0
        public int Alta(Inmueble entidad)
        {
            int res = -1;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"INSERT INTO Inmuebles (Direccion, Ambientes, Precio, Tipo, Uso, Disponible, PropietarioId) " +
                             $"VALUES ('{entidad.Direccion}', '{entidad.Ambientes}','{entidad.Precio}','{entidad.Tipo}','{entidad.Uso}','1','{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.Id = Convert.ToInt32(id);
                    connection.Close();
                }
            }
            return(res);
        }
コード例 #5
0
        public int Alta(Inmueble p)
        {
            int res = -1;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"INSERT INTO Inmuebles (Direccion, Ambientes, Superficie, Latitud, Longitud,PropietarioId,EstaPublicado,EstaHabilitado) " +
                             $"VALUES ('{p.Direccion}', '{p.Ambientes}','{p.Superficie}','{p.Latitud}','{p.Longitud}','1','1','1')";
                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();
                    p.inmuebleId = Convert.ToInt32(id);
                    connection.Close();
                }
            }
            return(res);
        }
コード例 #6
0
        public Inmueble ObtenerPorId(int id)
        {
            Inmueble entidad = null;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"SELECT Id, Direccion, Ambientes, Superficie, Latitud, Longitud, PropietarioId, p.Nombre, p.Apellido" +
                             $" FROM Inmuebles i INNER JOIN Propietarios p ON i.PropietarioId = p.IdPropietario" +
                             $" WHERE 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())
                    {
                        entidad = new Inmueble
                        {
                            Id            = 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);
        }
コード例 #7
0
        public IList <Inmueble> ObtenerTodos()
        {
            IList <Inmueble> res = new List <Inmueble>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = "SELECT Id, 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
                        {
                            Id            = 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);
        }
コード例 #8
0
        public IList <Inmueble> BuscarDisponibles()
        {
            IList <Inmueble> res = new List <Inmueble>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"SELECT IdInmueble, Direccion, Ambientes, Tipo, Uso, Precio, Disponible, Inmueble.IdPropietario, Propietario.Nombre, Propietario.Apellido FROM Inmueble INNER JOIN Propietario ON Propietario.IdPropietario=Inmueble.IdPropietario WHERE Disponible='Si'";

                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),
                            Ambientes   = reader.GetInt32(2),
                            Tipo        = reader.GetString(3),
                            Uso         = reader.GetString(4),
                            Precio      = reader.GetInt32(5),
                            Disponible  = reader.GetString(6),
                            Propietario = new Propietario
                            {
                                IdPropietario = reader.GetInt32(7),
                                Nombre        = reader.GetString(8),
                                Apellido      = reader.GetString(9)
                            }
                        };
                        res.Add(i);
                    }
                    connection.Close();
                }
            }
            return(res);
        }
コード例 #9
0
        public Inmueble ObtenerPorId(int id)
        {
            Inmueble p = null;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"SELECT IdInmueble, Direccion, Ambientes, Tipo, Uso, Precio, Disponible, Inmueble.IdPropietario, Propietario.Nombre, Propietario.Apellido FROM Inmueble JOIN Propietario ON(Propietario.IdPropietario=Inmueble.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())
                    {
                        p = new Inmueble
                        {
                            IdInmueble  = reader.GetInt32(0),
                            Direccion   = reader.GetString(1),
                            Ambientes   = reader.GetInt32(2),
                            Tipo        = reader.GetString(3),
                            Uso         = reader.GetString(4),
                            Precio      = reader.GetInt32(5),
                            Disponible  = reader.GetString(6),
                            Propietario = new Propietario
                            {
                                IdPropietario = reader.GetInt32(7),
                                Nombre        = reader.GetString(8),
                                Apellido      = reader.GetString(9)
                            }
                        };
                    }
                    connection.Close();
                }
            }
            return(p);
        }
コード例 #10
0
        public int Modificacion(Inmueble p)
        {
            int res = -1;

            using (SqlConnection connection = new SqlConnection(connectionString)) {
                string sql = $"UPDATE Inmuebles SET Direccion=@direccion, Disponible=@disponible, Ambientes =@ambientes, Categoria=@categoria, Uso=@uso, Transaccion=@transaccion, Precio=@precio " +
                             $"WHERE Id = {p.Id}";
                using (SqlCommand command = new SqlCommand(sql, connection)) {
                    command.Parameters.Add("@direccion", SqlDbType.VarChar).Value   = p.Direccion;
                    command.Parameters.Add("@disponible", SqlDbType.Int).Value      = p.Disponible;
                    command.Parameters.Add("@ambientes", SqlDbType.Int).Value       = p.Ambientes;
                    command.Parameters.Add("@categoria", SqlDbType.VarChar).Value   = p.Categoria;
                    command.Parameters.Add("@uso", SqlDbType.VarChar).Value         = p.Uso;
                    command.Parameters.Add("@transaccion", SqlDbType.VarChar).Value = p.Transaccion;
                    command.Parameters.Add("@precio", SqlDbType.Decimal).Value      = p.Precio;
                    command.CommandType = CommandType.Text;
                    connection.Open();
                    res = command.ExecuteNonQuery();
                    connection.Close();
                }
            }
            return(res);
        }
コード例 #11
0
        public Inmueble ObtenerPorId(int id)
        {
            Inmueble p = null;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"SELECT inmuebleId,Direccion, Ambientes, Superficie, Latitud, Longitud,PropietarioId,EstaPublicado,EstaHabilitado" +
                             $" FROM Inmuebles WHERE 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();
                    while (reader.Read())
                    {
                        p = new Inmueble
                        {
                            inmuebleId     = reader.GetInt32(0),
                            Direccion      = reader.GetString(1),
                            Ambientes      = reader.GetInt32(2),
                            Superficie     = reader.GetInt32(3),
                            Latitud        = reader.GetString(4),
                            Longitud       = reader.GetString(5),
                            PropietarioId  = reader.GetInt32(6),
                            EstaPublicado  = reader.GetBoolean(7),
                            EstaHabilitado = reader.GetBoolean(8),
                        };

                        return(p);
                    }
                    connection.Close();
                }
            }
            return(p);
        }
コード例 #12
0
        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 Id = {inmueble.Id}";
                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);
        }
コード例 #13
0
 public Inmueble FinalizarContrato(Inmueble i)
 {
     throw new NotImplementedException();
 }
コード例 #14
0
 public Inmueble Update(Inmueble i)
 {
     throw new NotImplementedException();
 }