Ejemplo n.º 1
0
        public static Venue Find(int id)
        {
            SqlConnection conn = DB.Connection();
              conn.Open();

              SqlCommand cmd = new SqlCommand("SELECT * FROM venues WHERE id = @VenueId;", conn);
              SqlParameter venueIdParameter = new SqlParameter();
              venueIdParameter.ParameterName = "@VenueId";
              venueIdParameter.Value = id.ToString();
              cmd.Parameters.Add(venueIdParameter);
              SqlDataReader rdr = cmd.ExecuteReader();

              int foundVenueId = 0;
              string foundVenueName = null;

              while(rdr.Read())
              {
            foundVenueId = rdr.GetInt32(0);
            foundVenueName = rdr.GetString(1);
              }
              Venue foundVenue = new Venue(foundVenueName, foundVenueId);

              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return foundVenue;
        }
Ejemplo n.º 2
0
 public void T2_Equal_ReturnsTrueIfNamesAreTheSame()
 {
     //arrange, act
       Venue firstVenue = new Venue("Pheonix");
       Venue secondVenue = new Venue("Pheonix");
       //Assert
       Assert.Equal(firstVenue, secondVenue);
 }
Ejemplo n.º 3
0
 public void T5_Find_FindNameInDatabase()
 {
     //arrange
       Venue testVenue = new Venue("Pheonix");
       testVenue.Save();
       //act
       Venue foundVenue = Venue.Find(testVenue.GetId());
       //Assert
       Assert.Equal(testVenue, foundVenue);
 }
Ejemplo n.º 4
0
 public void T3_Test_Save_SavesToDatabase()
 {
     //arrange
       Venue testVenue = new Venue("Pheonix");
       //act
       testVenue.Save();
       List<Venue> result = Venue.GetAll();
       List<Venue> testList = new List<Venue>{testVenue};
       //Assert
       Assert.Equal(testList, result);
 }
Ejemplo n.º 5
0
        public void T4_Save_AsignsIdToObject()
        {
            //arrange
              Venue newVenue = new Venue("Pheonix");
              //action
              newVenue.Save();
              Venue savedVenue = Venue.GetAll()[0];

              int result = savedVenue.GetId();
              int testId = newVenue.GetId();
              //assert
              Assert.Equal(testId, result);
        }
Ejemplo n.º 6
0
 public void T6_Update_UpdatesVenueInDatabase()
 {
     //Arrange
       string name = "Pheonix";
       Venue testVenue = new Venue(name);
       testVenue.Save();
       string newName = "Rock Candy";
       //Act
       testVenue.Update(newName);
       string result = testVenue.GetName();
       //Assert
       Assert.Equal(newName, result);
 }
Ejemplo n.º 7
0
        public void T9_Delete_DeletesVenueFromDB()
        {
            Venue testVenue1 = new Venue("Paramont");
              testVenue1.Save();
              Venue testVenue2 = new Venue("HD Hotspurs");
              testVenue2.Save();

              testVenue1.Delete();

              List<Venue> result = Venue.GetAll();
              List<Venue> testVenues = new List<Venue> {testVenue2};

              Assert.Equal(testVenues, result);
        }
Ejemplo n.º 8
0
        public void T6_AddBandToVenue_True()
        {
            Venue testVenue = new Venue("Paramont");
              testVenue.Save();

              Band testBand = new Band("GNR");
              testBand.Save();

              Band testBand2 = new Band("Primus");
              testBand2.Save();

              testVenue.AddBands(testBand);
              testVenue.AddBands(testBand2);
              List<Band> allBand= Band.GetAll();
              List<Band> result = testVenue.GetBands();
              List<Band> testList = new List<Band>{testBand,testBand2};

              Assert.Equal(testList, result);
        }
Ejemplo n.º 9
0
        public void T7_AddVenueToBand_True()
        {
            Band testBand = new Band("GNR");
              testBand.Save();

              Venue testVenue = new Venue("Paramont");
              testVenue.Save();

              Venue testVenue2 = new Venue("Rock Candy");
              testVenue2.Save();

              testBand.AddVenues(testVenue);
              testBand.AddVenues(testVenue2);
              List<Venue> allVenue = Venue.GetAll();
              List<Venue> result = testBand.GetVenues();
              List<Venue> testList = new List<Venue>{testVenue,testVenue2};

              Assert.Equal(testList, result);
        }
Ejemplo n.º 10
0
        public HomeModule()
        {
            Get["/"] = _ => {
            List<Venue> AllVenues = Venue.GetAll();
            return View["index.cshtml", AllVenues];
              };

              Get["/bands"] = _ => {
            List<Band> AllBands = Band.GetAll();
            return View["bands.cshtml", AllBands];
              };

              Get["/venues"] = _ => {
            List<Venue> AllVenues = Venue.GetAll();
            return View["venues.cshtml", AllVenues];
              };

              Get["/venues/new"] = _ => {
            return View["venues_form.cshtml"];
              };

              Post["/venues/new"] = _ => {
            Venue newVenue = new Venue(Request.Form["venue-name"]);
            newVenue.Save();
            return View["success.cshtml"];
              };

              Get["/bands/new"] = _ => {
            return View["bands_form.cshtml"];
              };

              Post["/bands/new"] = _ => {
            Band newBand = new Band(Request.Form["band-name"]);
            newBand.Save();
            return View["success.cshtml"];
              };

              Post["/bands/delete"] = _ => {
            Band.DeleteAll();
            return View["cleared.cshtml"];
              };

              Get["/venues/{id}"] = parameters => {
            Dictionary<string, object> model = new Dictionary<string, object>();
            var SelectedVenue = Venue.Find(parameters.id);
            var VenueBands = SelectedVenue.GetBands();
            model.Add("venue", SelectedVenue);
            model.Add("bands", VenueBands);
            return View["venue.cshtml", model];
              };

              Get["venue/edit/{id}"] = parameters => {
            Venue SelectedVenue = Venue.Find(parameters.id);
            return View["venue_edit.cshtml", SelectedVenue];
              };

              Patch["venue/edit/{id}"] = parameters => {
            Venue SelectedVenue = Venue.Find(parameters.id);
            SelectedVenue.Update(Request.Form["venue-name"]);
            return View["success.cshtml"];
              };

              Get["venue/delete/{id}"] = parameters => {
            Venue SelectedVenue = Venue.Find(parameters.id);
            return View["venue_delete.cshtml", SelectedVenue];
              };

              Delete["venue/delete/{id}"] = parameters => {
            Venue SelectedVenue = Venue.Find(parameters.id);
            SelectedVenue.Delete();
            return View["success.cshtml"];
              };

              Get["bands/{id}"]=parameters=>{
            Dictionary<string, object> model = new Dictionary<string, object>();
            Band selectedBand = Band.Find(parameters.id);
            List<Venue> bandVenues = selectedBand.GetVenues();
            List<Venue> allVenues = Venue.GetAll();
            model.Add("band",selectedBand);
            model.Add("bandVenues",bandVenues);
            model.Add("allVenues",allVenues);
            return View["band.cshtml",model];
              };

              Get["venues/{id}"] = parameters => {
            Dictionary<string, object> model = new Dictionary<string, object>();
            Venue selectedVenue = Venue.Find(parameters.id);
            List<Band> venueBands = selectedVenue.GetBands();
            List<Band> allBands = Band.GetAll();
            model.Add("venue", selectedVenue);
            model.Add("venueBands", venueBands);
            model.Add("allBands", allBands);
            return View["venue.cshtml", model];
              };

              Post["band/add_venue"] = _ =>{
            Venue venue= Venue.Find(Request.Form["venue-id"]);
            Band band = Band.Find(Request.Form["band-id"]);
            band.AddVenues(venue);
            return View["success.cshtml"];
              };

              Post["venue/add_band"] = _ => {
            Venue venue = Venue.Find(Request.Form["venue-id"]);
            Band band = Band.Find(Request.Form["band-id"]);
            venue.AddBands(band);
            return View["success.cshtml"];
              };
        }
Ejemplo n.º 11
0
        public HomeModule()
        {
            Get["/"] = _ => {
                List <Venue> AllVenues = Venue.GetAll();
                return(View["index.cshtml", AllVenues]);
            };

            Get["/bands"] = _ => {
                List <Band> AllBands = Band.GetAll();
                return(View["bands.cshtml", AllBands]);
            };

            Get["/venues"] = _ => {
                List <Venue> AllVenues = Venue.GetAll();
                return(View["venues.cshtml", AllVenues]);
            };

            Get["/venues/new"] = _ => {
                return(View["venues_form.cshtml"]);
            };

            Post["/venues/new"] = _ => {
                Venue newVenue = new Venue(Request.Form["venue-name"]);
                newVenue.Save();
                return(View["success.cshtml"]);
            };

            Get["/bands/new"] = _ => {
                return(View["bands_form.cshtml"]);
            };

            Post["/bands/new"] = _ => {
                Band newBand = new Band(Request.Form["band-name"]);
                newBand.Save();
                return(View["success.cshtml"]);
            };

            Post["/bands/delete"] = _ => {
                Band.DeleteAll();
                return(View["cleared.cshtml"]);
            };

            Get["/venues/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var SelectedVenue = Venue.Find(parameters.id);
                var VenueBands    = SelectedVenue.GetBands();
                model.Add("venue", SelectedVenue);
                model.Add("bands", VenueBands);
                return(View["venue.cshtml", model]);
            };

            Get["venue/edit/{id}"] = parameters => {
                Venue SelectedVenue = Venue.Find(parameters.id);
                return(View["venue_edit.cshtml", SelectedVenue]);
            };

            Patch["venue/edit/{id}"] = parameters => {
                Venue SelectedVenue = Venue.Find(parameters.id);
                SelectedVenue.Update(Request.Form["venue-name"]);
                return(View["success.cshtml"]);
            };

            Get["venue/delete/{id}"] = parameters => {
                Venue SelectedVenue = Venue.Find(parameters.id);
                return(View["venue_delete.cshtml", SelectedVenue]);
            };

            Delete["venue/delete/{id}"] = parameters => {
                Venue SelectedVenue = Venue.Find(parameters.id);
                SelectedVenue.Delete();
                return(View["success.cshtml"]);
            };

            Get["bands/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Band         selectedBand         = Band.Find(parameters.id);
                List <Venue> bandVenues           = selectedBand.GetVenues();
                List <Venue> allVenues            = Venue.GetAll();
                model.Add("band", selectedBand);
                model.Add("bandVenues", bandVenues);
                model.Add("allVenues", allVenues);
                return(View["band.cshtml", model]);
            };

            Get["venues/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Venue       selectedVenue         = Venue.Find(parameters.id);
                List <Band> venueBands            = selectedVenue.GetBands();
                List <Band> allBands = Band.GetAll();
                model.Add("venue", selectedVenue);
                model.Add("venueBands", venueBands);
                model.Add("allBands", allBands);
                return(View["venue.cshtml", model]);
            };

            Post["band/add_venue"] = _ => {
                Venue venue = Venue.Find(Request.Form["venue-id"]);
                Band  band  = Band.Find(Request.Form["band-id"]);
                band.AddVenues(venue);
                return(View["success.cshtml"]);
            };

            Post["venue/add_band"] = _ => {
                Venue venue = Venue.Find(Request.Form["venue-id"]);
                Band  band  = Band.Find(Request.Form["band-id"]);
                venue.AddBands(band);
                return(View["success.cshtml"]);
            };
        }
Ejemplo n.º 12
0
 public void Dispose()
 {
     Band.DeleteAll();
     Venue.DeleteAll();
 }
Ejemplo n.º 13
0
        //Functions
        public static List<Venue> GetAll()
        {
            List<Venue> allVenues = new List<Venue>{};

              SqlConnection conn = DB.Connection();
              conn.Open();

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

              while (rdr.Read())
              {
            int venueId = rdr.GetInt32(0);
            string venueName = rdr.GetString(1);
            Venue newVenue = new Venue(venueName, venueId);
            allVenues.Add(newVenue);
              }
              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return allVenues;
        }
Ejemplo n.º 14
0
        public List<Venue> GetVenues()
        {
            SqlConnection conn = DB.Connection();
              conn.Open();

              SqlCommand cmd = new SqlCommand("SELECT venues.* FROM bands JOIN venues_bands ON (bands.id = venues_bands.band_id) JOIN venues ON (venues_bands.venue_id = venues.id) WHERE bands.id = @BandId;", conn);
              SqlParameter BandIdParameter = new SqlParameter();
              BandIdParameter.ParameterName = "@BandId";
              BandIdParameter.Value = this.GetId().ToString();

              cmd.Parameters.Add(BandIdParameter);
              SqlDataReader rdr = cmd.ExecuteReader();

              List<Venue> venues = new List<Venue>{};

              while (rdr.Read())
              {
            int venueId = rdr.GetInt32(0);
            string venueName = rdr.GetString(1);
            Venue newVenue = new Venue(venueName, venueId);
            venues.Add(newVenue);
              }
              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return venues;
        }
Ejemplo n.º 15
0
        public void T8_GetVenues_ReturnsAllVenueBand()
        {
            Band testBand = new Band("GNR");
              testBand.Save();

              Venue testVenue1 = new Venue("Paramont");
              testVenue1.Save();

              Venue testVenue2 = new Venue("Rock Candy");
              testVenue2.Save();

              Venue testVenue3 = new Venue("Cafe Arizona");
              testVenue3.Save();

              Venue testVenue4 = new Venue("Joes Bar and Grill");
              testVenue4.Save();

              testBand.AddVenues(testVenue1);

              List<Venue> result = testBand.GetVenues();
              List<Venue> testList= new List<Venue>{testVenue1};

              Assert.Equal(testList,result);
        }
Ejemplo n.º 16
0
        public void AddVenues(Venue newVenue)
        {
            SqlConnection conn = DB.Connection();
              conn.Open();

              SqlCommand cmd = new SqlCommand("INSERT INTO venues_bands (venue_id, band_id) VALUES (@VenueId,@BandId)",conn);

              SqlParameter venueIdParameter = new SqlParameter();
              venueIdParameter.ParameterName= "@VenueId";
              venueIdParameter.Value= newVenue.GetId();

              SqlParameter bandIdParameter = new SqlParameter();
              bandIdParameter.ParameterName= "@BandId";
              bandIdParameter.Value= this.GetId();

              cmd.Parameters.Add(venueIdParameter);
              cmd.Parameters.Add(bandIdParameter);

              cmd.ExecuteNonQuery();

              if(conn != null)
              {
            conn.Close();
              }
        }
Ejemplo n.º 17
0
        public void T7_GetBands_ReturnsAllBandVenues()
        {
            Venue testVenue = new Venue("Paramont");
              testVenue.Save();

              Band testBand1 = new Band("GNR");
              testBand1.Save();

              Band testBand2 = new Band("Primus");
              testBand2.Save();

              Band testBand3 = new Band("The Strokes");
              testBand3.Save();

              Band testBand4 = new Band("Rob Zombie");
              testBand4.Save();

              testVenue.AddBands(testBand1);

              List<Band> result = testVenue.GetBands();
              List<Band> testList= new List<Band>{testBand1};

              Assert.Equal(testList,result);
        }