public bool NewCoalition(Coalitie c) { try { Database.Conn.Open(); using (SqlCommand cmd = new SqlCommand("NewCoalition")) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Naam", c.Naam); cmd.Parameters.AddWithValue("@PremierID", c.PremierId); cmd.ExecuteNonQuery(); } using (SqlCommand cmd = new SqlCommand("AddCoalitionParties")) { foreach (Partij p in c.Partijen) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@PartijId", p.Id); cmd.ExecuteNonQuery(); } } return(true); } catch (Exception e) { Console.WriteLine(e.ToString()); return(false); } finally { Database.Conn.Close(); } }
public Coalitie GetById(int id) { Coalitie c = new Coalitie(); List <Partij> partijen = partijRepo.GetAll(); try { Database.Conn.Open(); //string queryLid = "SELECT * FROM Lid WHERE PartijID = @id"; //using (SqlCommand cmd = new SqlCommand(queryLid, Database.Conn)) //{ // cmd.Parameters.AddWithValue("@id", id); // using (SqlDataReader r = cmd.ExecuteReader()) // { // while (r.Read()) // { // leden.Add(CreateLidFromReader(r)); // } // } //} //string queryPartij = "SELECT * FROM Partij WHERE PartijID = @id"; //using (SqlCommand cmd = new SqlCommand(queryPartij, Database.Conn)) //{ // cmd.Parameters.AddWithValue("@id", id); // using (SqlDataReader r = cmd.ExecuteReader()) // { // while (r.Read()) // { // partijen.Add(CreatePartijFromReader(r, leden)); // } // } //} string queryCoalitie = "SELECT * FROM Coalitie c INNER JOIN Coalitie_Partij CP ON c.CoalitieID = CP.CoalitieID INNER JOIN Partij P ON P.PartijID = CP.PartijID WHERE C.CoalitieID = @id"; using (SqlCommand cmd = new SqlCommand(queryCoalitie, Database.Conn)) { using (SqlDataReader r = cmd.ExecuteReader()) { cmd.Parameters.AddWithValue("@id", id); while (r.Read()) { return(CreateCoalitieFromReader(r, partijen)); } } } return(c); } catch (Exception e) { Console.WriteLine(e.ToString()); return(null); } finally { Database.Conn.Close(); } }
public bool NewCoalition(Coalitie c) { return(context.NewCoalition(c)); }