Exemplo n.º 1
0
 public void Insert(Reservering reservering)
 {
     using (SqlConnection conn = new SqlConnection(ConnectionString))
     {
         StoelRepository SRep = new StoelRepository(new MssqlStoelContext());
         conn.Open();
         string     query = "INSERT INTO dbo.reservering (Stoel_ID, datum, prijs) VALUES (@stoel, @datum, @prijs)";
         SqlCommand cmd   = new SqlCommand(query, conn);
         cmd.Parameters.AddWithValue("@stoel", reservering.Stoelen);
         cmd.Parameters.AddWithValue("@datum", reservering.Voorstelling.Starttijd);
         cmd.Parameters.AddWithValue("@prijs", reservering.Prijs);
         cmd.ExecuteNonQuery();
         string        query2 = "Select * FROM dbo.reservering";
         SqlCommand    cmd2   = new SqlCommand(query2, conn);
         SqlDataReader reader = cmd2.ExecuteReader();
         List <int>    IdList = new List <int>();
         if (reader != null && reader.HasRows)
         {
             while (reader.Read())
             {
                 IdList.Add(reader.GetInt32(reader.GetOrdinal("ID")));
             }
         }
         foreach (Stoel s in reservering.Voorstelling.Zl.Stoelen)
         {
             SRep.UpdateStoel(s, IdList.Max());
         }
         conn.Close();
     }
 }
Exemplo n.º 2
0
        public Zaal GetById(int id)
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                StoelRepository SRep = new StoelRepository(new MssqlStoelContext());
                conn.Open();
                string query = "SELECT * FROM dbo.zaal WHERE ID = @ID";

                SqlCommand cmd = new SqlCommand(query, conn);
                cmd.Parameters.AddWithValue("ID", id);
                SqlDataReader reader = cmd.ExecuteReader();
                Zaal          z      = new Zaal();
                while (reader.Read())
                {
                    z.Id      = id;
                    z.Grootte = reader.GetInt32(reader.GetOrdinal("grootte"));
                    z.Nummer  = reader.GetInt32(reader.GetOrdinal("nummer"));
                    z.Stoelen = SRep.GetByZaalId(reader.GetInt32(reader.GetOrdinal("ID")));
                }
                conn.Close();
                return(z);
            }
        }