public static List<Band> GetAll()
        {
            List<Band> allBands = new List<Band>{};
              SqlConnection conn = DB.Connection();
              SqlDataReader rdr = null;
              conn.Open();

              SqlCommand cmd = new SqlCommand("SELECT * FROM bands;", conn);
              rdr = cmd.ExecuteReader();

              while(rdr.Read())
              {
            int bandId = rdr.GetInt32(0);
            string name = rdr.GetString(1);
            Band newBand = new Band(name, bandId);
            allBands.Add(newBand);
              }
              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return allBands;
        }
        public static Band Find(int bandId)
        {
            SqlConnection conn = DB.Connection();
              SqlDataReader rdr;
              conn.Open();

              SqlCommand cmd = new SqlCommand("SELECT * FROM bands WHERE id = @bandId;", conn);

              SqlParameter bandIdParameter = new SqlParameter();
              bandIdParameter.ParameterName = "@bandId";
              bandIdParameter.Value = bandId.ToString();

              cmd.Parameters.Add(bandIdParameter);

              int foundBandId = 0;
              string foundBandName = null;
              rdr = cmd.ExecuteReader();

              while(rdr.Read())
              {
            foundBandId = rdr.GetInt32(0);
            foundBandName = rdr.GetString(1);
              }
              Band newBand = new Band(foundBandName, foundBandId);
              if (rdr != null) rdr.Close();
              if (conn != null) conn.Close();
              return newBand;
        }
        public void Band_Update_UpdatesBand()
        {
            Band firstBand = new Band("Ween");
              firstBand.Save();

              firstBand.Update("Dexy's Midnight Runners");

              Band resultBand = Band.Find(firstBand.GetId());

              Assert.Equal("Dexy's Midnight Runners", resultBand.GetName());
        }
        public void Test_DeleteOne_DeletesASpecificBandObject()
        {
            //Arrange
              Band firstBand = new Band("Ween");
              firstBand.Save();
              Band secondBand = new Band("Dexy's Midnight Runners");
              secondBand.Save();

              //Act
              secondBand.Delete();
              List<Band> expectedBand = new List<Band> {firstBand};
              List<Band> testBand= Band.GetAll();

              //Assert
              Assert.Equal(expectedBand, testBand);
        }
        public void Test_AddShow_AddsAShowWithBandAndVenue()
        {
            //Arrange
              Band testBand = new Band("Ween");
              testBand.Save();
              Venue testVenue = new Venue("Chad's");
              testVenue.Save();

              //Act
              testVenue.AddShow(testBand.GetId(), testDate);
              List<Venue> expectedVenue = new List<Venue> {testVenue};
              List<Venue> result= testBand.GetVenues();

              //Assert
              Assert.Equal(expectedVenue, result);
        }
        public void Test_Find_ReturnsASpecificBandObject()
        {
            //Arrange
              Band newBand = new Band("Ween");
              newBand.Save();

              //Act
              Band foundBand = Band.Find(newBand.GetId());

              //Assert
              Assert.Equal(newBand, foundBand);
        }
        public void Test_Save_SavesCorrectObjectToDatabase()
        {
            //Arrange
              Band newBand = new Band("Ween");

              //Act
              newBand.Save();
              Band savedBand = Band.GetAll()[0];

              //Assert
              Assert.Equal(newBand, savedBand);
        }
        public List<Band> GetBands()
        {
            SqlConnection conn = DB.Connection();
              SqlDataReader rdr = null;
              conn.Open();

              SqlCommand cmd = new SqlCommand("SELECT bands.* FROM venues JOIN shows ON (shows.venue_id = venues.id) JOIN bands ON (shows.band_id = bands.id) WHERE venue_id = @VenueId ORDER BY shows.date DESC;", conn);

              SqlParameter venueIdParameter = new SqlParameter();
              venueIdParameter.ParameterName = "@VenueId";
              venueIdParameter.Value = this.GetId();
              cmd.Parameters.Add(venueIdParameter);

              rdr=cmd.ExecuteReader();

              List<Band> foundBands = new List<Band>{};

              while(rdr.Read())
              {
            int foundId = rdr.GetInt32(0);
            string foundName = rdr.GetString(1);
            Band foundBand = new Band(foundName, foundId);
            foundBands.Add(foundBand);
              }

              if(rdr!=null) rdr.Close();
              if(conn!=null) conn.Close();

              return foundBands;
        }
Exemple #9
0
 public void Dispose()
 {
     Venue.DeleteAll();
     Band.DeleteAll();
 }