private static void DeleteHóspede() { int NIF; Console.Write("NIF: "); NIF = int.Parse(Console.ReadLine()); using (var context = new GlampinhoEF()) { context.deleteHospede(NIF); } }
private static void DeleteParque() { string nomeParque; List <int> hóspedes, estadas; ParqueCampismo parque = new ParqueCampismo(); Console.Write("Nome Parque: "); nomeParque = Console.ReadLine(); parque.nome = nomeParque; using (var context = new GlampinhoEF()) { hóspedes = context.Database.SqlQuery <int>( "SELECT DISTINCT NIF FROM HóspedeEstada \n" + "EXCEPT\n" + "SELECT DISTINCT NIF FROM HóspedeEstada INNER JOIN ( SELECT id FROM AlojamentoEstada WHERE nomeParque<>@p0 ) AS A ON A.id=HóspedeEstada.id", nomeParque).ToList(); } hóspedes.ForEach((hóspede) => { using (var context = new GlampinhoEF()) { context.deleteHospede(hóspede); } }); using (var context = new GlampinhoEF()) { estadas = context.Database.SqlQuery <int>( "SELECT A.id FROM Estada INNER JOIN(SELECT * FROM AlojamentoEstada WHERE nomeParque = @p0) AS A ON Estada.id = A.id", nomeParque).ToList(); context.Entry(parque).State = EntityState.Deleted; context.SaveChanges(); } estadas.ForEach((estadaId) => { Estada estada = new Estada(); estada.id = estadaId; using (var context = new GlampinhoEF()) { context.Entry(estada).State = EntityState.Deleted; context.SaveChanges(); } }); }