Beispiel #1
0
        // a method to return a single Venue record with an id
        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;
        }
 public void Test_Save_Find_Update()
 {
     Venue testVenue = new Venue("123 Fakestreet", "Fakename Center");
       testVenue.Save();
       testVenue.Update(new List<string> {"name"}, new List<object> {"The Fakename Center"});
       Assert.Equal("The Fakename Center", Venue.Find(testVenue.id).name);
 }
 public HomeModule()
 {
     Get["/"] = _ => {
     return View["index.cshtml"];
       };
       Get["/bands"] = _ => {
     return View["bands.cshtml", Band.GetAll()];
       };
       Get["/venues"] = _ => {
     return View["venues.cshtml", Venue.GetAll()];
       };
       Post["/bands"] = _ => {
     Band newBand = new Band(Request.Form["genre"], Request.Form["name"]);
     newBand.Save();
     return View["bands.cshtml", Band.GetAll()];
       };
       Post["/venues"] = _ => {
     Venue newVenue = new Venue(Request.Form["location"], Request.Form["name"]);
     newVenue.Save();
     return View["venues.cshtml", Venue.GetAll()];
       };
       Get["/bands/{id}"] = parameters => {
     return View["band.cshtml", new List<object> {Band.Find(parameters.id), Venue.GetAll()}];
       };
       Get["/venues/{id}"] = parameters => {
     return View["venue.cshtml", new List<object> {Venue.Find(parameters.id), Band.GetAll()}];
       };
       Post["/bands/{id}"] = parameters => {
     Venue selectedVenue = Venue.Find((int)Request.Form["venue"]);
     Band selectedBand = Band.Find(parameters.id);
     selectedBand.AddPerformance(selectedVenue.id);
     return View["band.cshtml", new List<object> {Band.Find(parameters.id), Venue.GetAll()}];
       };
       Patch["/bands/{id}"] = parameters => {
     Band selectedBand = Band.Find(parameters.id);
     selectedBand.Update(new List<string> {"name", "genre"}, new List<object> {(string)Request.Form["name"], (string)Request.Form["genre"]});
     return View["band.cshtml", new List<object> {Band.Find(parameters.id), Venue.GetAll()}];
       };
       Delete["/bands/{id}"] = parameters => {
     Band selectedBand = Band.Find(parameters.id);
     selectedBand.Delete(new string[] {"performances"}, new string[] {"band_id"});
     return View["bands.cshtml", Band.GetAll()];
       };
       Post["/venues/{id}"] = parameters => {
     Band selectedBand = Band.Find((int)Request.Form["band"]);
     selectedBand.AddPerformance(parameters.id);
     return View["venue.cshtml", new List<object> {Venue.Find(parameters.id), Band.GetAll()}];
       };
       Patch["/venues/{id}"] = parameters => {
     Venue selectedVenue = Venue.Find(parameters.id);
     selectedVenue.Update(new List<string> {"name", "location"}, new List<object> {(string)Request.Form["name"], (string)Request.Form["location"]});
     return View["venue.cshtml", new List<object> {Venue.Find(parameters.id), Band.GetAll()}];
       };
       Delete["/venues/{id}"] = parameters => {
     Venue selectedVenue = Venue.Find(parameters.id);
     selectedVenue.Delete(new string[] {"performances"}, new string[] {"venue_id"});
     return View["venues.cshtml", Venue.GetAll()];
       };
 }
Beispiel #4
0
 public void Test_Equal_ReturnsTrueIfNamessAreTheSame()
 {
     //Arrange, Act
       Venue firstVenue = new Venue("The Moore");
       Venue secondVenue = new Venue("The Moore");
       //Assert
       Assert.Equal(firstVenue, secondVenue);
 }
Beispiel #5
0
        public void T2_Equal_ReturnsTrueForSameName()
        {
            // Arrange, act
              Venue firstVenue = new Venue("A");
              Venue secondVenue = new Venue("A");

              // Assert
              Assert.Equal(firstVenue, secondVenue);
        }
 public void Test_GetVenues()
 {
     Venue testVenue = new Venue("123 Fakestreet", "Fakename Center");
       testVenue.Save();
       Band testBand = new Band("Pazz", "Jeff and the Baboons");
       testBand.Save();
       testBand.AddPerformance(testVenue.id);
       Assert.Equal(testVenue.id, testBand.GetVenues()[0].id);
 }
        public void Test_Find_FindsVenueInDatabase()
        {
            Venue testVenue = new Venue("Shatter Dome");
              testVenue.Save();

              Venue foundVenue = Venue.Find(testVenue.GetId());

              Assert.Equal(testVenue, foundVenue);
        }
 public HomeModule()
 {
     Get["/"] =_=> {
     List<Venue> AllVenues = Venue.GetAll();
     return View["index.cshtml", AllVenues];
       };
       Post["/venue/new"] =_=> {
     Venue NewVenue = new Venue(Request.Form["newVenue"]);
     NewVenue.Save();
     List<Venue> AllVenues = Venue.GetAll();
     return View["index.cshtml", AllVenues];
       };
       Patch["/venue/edit/{id}"] =parameters=> {
     Venue changeVenue = Venue.Find(parameters.id);
     changeVenue.SetName(Request.Form["newVenueName"]);
     changeVenue.Update();
     List<Venue> AllVenues = Venue.GetAll();
     return View["index.cshtml", AllVenues];
       };
       Delete["/venue/delete/{id}"] =parameters=> {
     Venue.Delete(parameters.id);
     List<Venue> AllVenues = Venue.GetAll();
     return View["index.cshtml", AllVenues];
       };
       Get["/band/all"] =_=> {
     List<Band> AllBands = Band.GetAll();
     return View["all_bands.cshtml", AllBands];
       };
       Post["/band/new"] =_=> {
     Band NewBand = new Band(Request.Form["newBand"]);
     NewBand.Save();
     List<Band> AllBands = Band.GetAll();
     return View["all_bands.cshtml", AllBands];
       };
       Get["/venue/{id}"] =parameters=> {
     Venue currentVenue = Venue.Find(parameters.id);
     return View["venue_bands.cshtml", currentVenue];
       };
       Post["/venue/{id}/add-band/new"] =parameters=> {
     Band newBand = new Band(Request.Form["newBand"]);
     newBand.Save();
     Venue currentVenue = Venue.Find(parameters.id);
     currentVenue.AddBand(newBand);
     return View["venue_bands.cshtml", currentVenue];
       };
       Get["/band/{id}"] =parameters=> {
     Band currentBand = Band.Find(parameters.id);
     return View["band_venues.cshtml", currentBand];
       };
       Post["/band/{id}/add-venue/new"] =parameters=> {
     Venue newVenue = new Venue(Request.Form["newVenue"]);
     newVenue.Save();
     Band currentBand = Band.Find(parameters.id);
     currentBand.AddVenue(newVenue);
     return View["band_venues.cshtml", currentBand];
       };
 }
Beispiel #9
0
        public void T3_Save_SavesVenueToDatabase()
        {
            // Arrange
              Venue testVenue = new Venue("A");
              testVenue.Save();

              // Act
              List<Venue> result = Venue.GetAll();
              List<Venue> testList = new List<Venue>{testVenue};

              // Assert
              Assert.Equal(testList, result);
        }
        public void Test_Delete_DeletesVenueFromDatabase()
        {
            Venue testVenue1 = new Venue("Shatter Dome");
              testVenue1.Save();
              Venue testVenue2 = new Venue("Belly of the Beast");
              testVenue2.Save();

              Venue.Delete(testVenue1.GetId());

              List<Venue> testList = new List<Venue>{testVenue2};
              List<Venue> resultList = Venue.GetAll();

              Assert.Equal(testList, resultList);
        }
        public void Test_AddVenue_AddsVenueToBand()
        {
            Band testBand = new Band("Frets on Fire", 1);
              testBand.Save();
              Venue testVenue = new Venue("Shatter Dome", 1);
              testVenue.Save();

              testBand.AddVenue(testVenue);

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

              Assert.Equal(testList, result);
        }
        public void Test_AddBand_AddsBandToVenue()
        {
            Band testBand = new Band("Frets on Fire");
              testBand.Save();
              Venue testVenue = new Venue("Shatter Dome");
              testVenue.Save();

              testVenue.AddBand(testBand);

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

              Assert.Equal(testList, result);
        }
Beispiel #13
0
 public void Test_Delete_DeletesVenueFromDatabase()
 {
     //Arrange
       string name1 = "El Corazon";
       Venue testVenue1 = new Venue(name1);
       testVenue1.Save();
       string name2 = "The Vogue";
       Venue testVenue2 = new Venue(name2);
       testVenue2.Save();
       //Act
       testVenue1.Delete();
       List<Venue> resultVenues = Venue.GetAll();
       List<Venue> testVenueList = new List<Venue> {testVenue2};
       //Assert
       Assert.Equal(testVenueList, resultVenues);
 }
Beispiel #14
0
        public void T4_Save_AssignsIdToCagetoryObject()
        {
            //Arrange

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

              //Act
              Venue savedVenue = Venue.GetAll()[0];

              int result = savedVenue.GetId();
              int testId = testVenue.GetId();

              //Assert
              Assert.Equal(testId, result);
        }
        public void Test_GetVenues_ReturnsAllBandVenues()
        {
            Band testBand = new Band("Frets on Fire", 1);
              testBand.Save();
              Venue testVenue1 = new Venue("Shatter Dome", 1);
              testVenue1.Save();
              Venue testVenue2 = new Venue("Belly of the Beast", 1);
              testVenue2.Save();

              testBand.AddVenue(testVenue1);
              testBand.AddVenue(testVenue2);

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

              Assert.Equal(testList, result);
        }
Beispiel #16
0
 public void Test_AddBand_AddsBandToVenue()
 {
     //Arrange
       Venue testVenue = new Venue("El Corazon");
       testVenue.Save();
       Band testBand = new Band("The Loud Mouths");
       testBand.Save();
       Band testBand2 = new Band("The People With Guitars ");
       testBand2.Save();
       //Act
       testVenue.AddBand(testBand);
       testVenue.AddBand(testBand2);
       List<Band> result = testVenue.GetBands();
       List<Band> testList = new List<Band>{testBand, testBand2};
       //Assert
       Assert.Equal(testList, result);
 }
        public void Test_GetBands_ReturnsAllBandBands()
        {
            Venue testVenue = new Venue("Shatter Dome");
              testVenue.Save();
              Band testBand1 = new Band("Frets on Fire");
              testBand1.Save();
              Band testBand2 = new Band("Crimson Typhoon and the Knife Heads");
              testBand2.Save();

              testVenue.AddBand(testBand1);
              testVenue.AddBand(testBand2);

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

              Assert.Equal(testList, result);
        }
Beispiel #18
0
        public void Test_AddVenue_AddsVenueToBand()
        {
            //Arrange
              Band testBand = new Band("The Loud Mouths");
              testBand.Save();
              Venue testVenue1 = new Venue("El Corazon");
              testVenue1.Save();
              Venue testVenue2 = new Venue("The NiteLite");
              testVenue2.Save();
              List<Venue> testList = new List<Venue>{testVenue1, testVenue2};
              //Act
              testBand.AddVenue(testVenue1);
              testBand.AddVenue(testVenue2);
              List<Venue> resultList = testBand.GetVenues();

              //Assert
              Assert.Equal(testList, resultList);
        }
Beispiel #19
0
        public void Test18_GetVenues_ReturnsAllBandVenues()
        {
            DateTime testTime = new DateTime(2016, 1, 1);

              Band testBand = new Band("A",testTime);
              testBand.Save();

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

              Venue testVenue2 = new Venue(" Stuff");
              testVenue2.Save();

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

              Assert.Equal(testList,result);
        }
Beispiel #20
0
        public void Test_AddVenue_AddsVenueToBand()
        {
            DateTime testTime = new DateTime(2016, 1, 1);

              //Arrange
              Band testBand = new Band("A",testTime);
              testBand.Save();

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

              //Act
              testBand.AddVenue(testVenue);
              List<Venue> result = testBand.GetVenues();
              List<Venue> testList = new List<Venue> {testVenue};

              //Assert
              Assert.Equal(testList, result);
        }
Beispiel #21
0
        public void Test_Delete_DeletesBandAssociationsFromDatabase()
        {
            //Arrange
              Venue testVenue = new Venue("Hello");
              testVenue.Save();
              DateTime testTime = new DateTime(2016, 1, 1);

              string testName = "A";
              Band testBand = new Band(testName,testTime);
              testBand.Save();

              //Act
              testBand.AddVenue(testVenue);
              testBand.Delete();

              List<Band> resultVenueBands = testVenue.GetBands();
              List<Band> testVenueBands = new List<Band> {};

              //Assert
              Assert.Equal(testVenueBands, resultVenueBands);
        }
Beispiel #22
0
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };

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

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

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

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

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

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

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

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

            Get["/venue/delete/{id}"] = parameters => {
                Venue        selectedVenue = Venue.Find(parameters.id);
                List <Venue> allVenues     = Venue.GetAll();
                return(View["venues.cshtml", allVenues]);
            };

            Delete["/venue/delete/{id}"] = parameters => {
                Venue selectedVenue = Venue.Find(parameters.id);
                selectedVenue.DeleteVenue();
                List <Venue> allVenues = Venue.GetAll();
                return(View["venues.cshtml", allVenues]);
            };

            Get["/venue/update/{id}"] = parameters => {
                Venue selectedVenue = Venue.Find(parameters.id);
                return(View["edit_venue.cshtml", selectedVenue]);
            };

            Post["/venue/update/{id}"] = parameters => {
                Venue selectedVenue = Venue.Find(parameters.id);
                return(View["edit_venue.cshtml", selectedVenue]);
            };

            Patch["/venue/update/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Venue selectedVenue = Venue.Find(parameters.id);
                selectedVenue.UpdateVenue(Request.Form["new-venue-name"]);
                List <Band> allBands   = Band.GetAll();
                List <Band> venueBands = selectedVenue.GetBands();
                model.Add("venue", selectedVenue);
                model.Add("allBands", allBands);
                model.Add("venueBands", venueBands);
                return(View["venue.cshtml", model]);
            };

            Post["/venue/add_band/{id}"] = parameters => {
                Band  band  = Band.Find(Request.Form["band-id"]);
                Venue venue = Venue.Find(Request.Form["venue-id"]);
                venue.AddBand(band);
                Dictionary <string, object> model = new Dictionary <string, object>();
                List <Band> allBands   = Band.GetAll();
                List <Band> venueBands = venue.GetBands();
                model.Add("venue", venue);
                model.Add("band", band);
                model.Add("allBands", allBands);
                model.Add("venueBands", venueBands);
                return(View["venue.cshtml", model]);
            };

            Post["/band/add_venue/{id}"] = parameters => {
                Band  band  = Band.Find(Request.Form["band-id"]);
                Venue venue = Venue.Find(Request.Form["venue-id"]);
                band.AddVenue(venue);
                List <Venue> allVenues            = Venue.GetAll();
                List <Venue> bandVenue            = band.GetVenues();
                Dictionary <string, object> model = new Dictionary <string, object>();
                model.Add("band", band);
                model.Add("allVenues", allVenues);
                model.Add("bandVenue", bandVenue);
                return(View["band.cshtml", model]);
            };
        }
        public HomeModule()
        {
            Get["/"] = _ => {
                Dictionary <string, object> model  = new Dictionary <string, object>();
                List <Venue>       allVenues       = Venue.GetAll();
                List <Band>        allBands        = Band.GetAll();
                List <Performance> allPerformances = Performance.GetAll();
                model.Add("venues", allVenues);
                model.Add("bands", allBands);
                model.Add("performances", allPerformances);
                return(View["index.cshtml", model]);
            };

            Post["/band_added"] = _ => {
                Band newBand = new Band(Request.Form["band-name"]);
                newBand.Save();
                Dictionary <string, object> model  = new Dictionary <string, object>();
                List <Venue>       allVenues       = Venue.GetAll();
                List <Band>        allBands        = Band.GetAll();
                List <Performance> allPerformances = Performance.GetAll();
                model.Add("venues", allVenues);
                model.Add("bands", allBands);
                model.Add("performances", allPerformances);
                return(View["index.cshtml", model]);
            };

            Post["/venue_added"] = _ => {
                Venue newVenue = new Venue(Request.Form["venue-name"]);
                newVenue.Save();
                Dictionary <string, object> model  = new Dictionary <string, object>();
                List <Venue>       allVenues       = Venue.GetAll();
                List <Band>        allBands        = Band.GetAll();
                List <Performance> allPerformances = Performance.GetAll();
                model.Add("venues", allVenues);
                model.Add("bands", allBands);
                model.Add("performances", allPerformances);
                return(View["index.cshtml", model]);
            };

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

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

            Patch["/venue/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Venue selectedVenue = Venue.Find(parameters.id);
                selectedVenue.Update(Request.Form["rename"]);
                List <Band> venueBands = selectedVenue.GetBands();
                model.Add("venue", selectedVenue);
                model.Add("bands", venueBands);
                return(View["venue.cshtml", model]);
            };

            Delete["/deleted/{id}"] = parameters => {
                Venue selectedVenue = Venue.Find(parameters.id);
                selectedVenue.DeleteAssociations();
                selectedVenue.Delete();
                Dictionary <string, object> model  = new Dictionary <string, object>();
                List <Venue>       allVenues       = Venue.GetAll();
                List <Band>        allBands        = Band.GetAll();
                List <Performance> allPerformances = Performance.GetAll();
                model.Add("venues", allVenues);
                model.Add("bands", allBands);
                model.Add("performances", allPerformances);
                return(View["index.cshtml", model]);
            };

            Post["/performance_added"] = _ => {
                Performance newPerformance = new Performance(Request.Form["performance-venue"], Request.Form["performance-band"], Request.Form["performance-date"]);
                newPerformance.Save();
                Dictionary <string, object> model  = new Dictionary <string, object>();
                List <Venue>       allVenues       = Venue.GetAll();
                List <Band>        allBands        = Band.GetAll();
                List <Performance> allPerformances = Performance.GetAll();
                model.Add("venues", allVenues);
                model.Add("bands", allBands);
                model.Add("performances", allPerformances);
                return(View["index.cshtml", model]);
            };

            Delete["/delete_all"] = _ => {
                Venue.DeleteAll();
                Band.DeleteAll();
                Performance.DeleteAll();
                Dictionary <string, object> model  = new Dictionary <string, object>();
                List <Venue>       allVenues       = Venue.GetAll();
                List <Band>        allBands        = Band.GetAll();
                List <Performance> allPerformances = Performance.GetAll();
                model.Add("venues", allVenues);
                model.Add("bands", allBands);
                model.Add("performances", allPerformances);
                return(View["index.cshtml", model]);
            };
        }
Beispiel #24
0
 public void Test_Find_FindsVenueInDatabase()
 {
     //Arrange
       Venue testVenue = new Venue("El Corazon");
       testVenue.Save();
       //Act
       Venue foundVenue = Venue.Find(testVenue.GetId());
       //Assert
       Assert.Equal(testVenue, foundVenue);
 }
Beispiel #25
0
        public void GetAll_DatabaseEmptyAtFirst_Empty()
        {
            int result = Venue.GetAll().Count;

            Assert.Equal(0, result);
        }
Beispiel #26
0
 public void Test_Update_UpdatesVenueInDatabase()
 {
     //Arrange
       string name = "The Vogue";
       Venue testVenue = new Venue(name);
       testVenue.Save();
       string newName = "The NiteLite";
       //Act
       testVenue.Update(newName);
       string result = testVenue.GetName();
       //Assert
       Assert.Equal(newName, result);
 }
Beispiel #27
0
 public void Test_Save_AssignsIdToObject()
 {
     //Arrange
       Venue testVenue = new Venue("The Neptune");
       //Act
       testVenue.Save();
       Venue savedVenue = Venue.GetAll()[0];
       int result = savedVenue.GetId();
       int testId = testVenue.GetId();
       //Assert
       Assert.Equal(testId, result);
 }
 public void Dispose()
 {
     Venue.DeleteAll();
     Band.DeleteAll();
     Performance.DeleteAll();
 }
Beispiel #29
0
        public void GetAll_VenueEmptyAtFirst_true()
        {
            int result = Venue.GetAll().Count;

            Assert.Equal(0, result);
        }
        public List<Venue> GetVenues()
        {
            SqlConnection conn = DB.Connection();
              conn.Open();
              SqlDataReader rdr;

              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();

              cmd.Parameters.Add(bandIdParameter);
              rdr = cmd.ExecuteReader();

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

              while (rdr.Read())
              {
            int thisVenueId = rdr.GetInt32(0);
            string venueName = rdr.GetString(1);
            Venue foundVenue = new Venue(venueName, thisVenueId);
            allVenues.Add(foundVenue);
              }
              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return allVenues;
        }
 public HomeModule()
 {
     Get["/"]       = _ => View["index.cshtml"];
     Get["/venues"] = _ => {
         List <Venue> allVenues = Venue.GetAll();
         return(View["venues.cshtml", allVenues]);
     };
     Get["/bands"] = _ => {
         List <Band> allBands = Band.GetAll();
         return(View["bands.cshtml", allBands]);
     };
     Get["/venues/new"] = _ => {
         return(View["venue_form.cshtml"]);
     };
     Get["/bands/new"] = _ => {
         return(View["band_form.cshtml"]);
     };
     Get["/bands/new/members"] = _ => {
         Dictionary <string, object> model = new Dictionary <string, object> {
         };
         model.Add("part2", true);
         model.Add("members", Request.Query["members-number"]);
         return(View["band_form.cshtml", model]);
     };
     Post["/bands/new"] = _ => {
         Band newBand = new Band(Request.Form["band-name"], Request.Form["members"]);
         newBand.Save();
         string membersValues = Request.Form["member-name"];
         if (membersValues != null)
         {
             string[] members = membersValues.Split(',');
             foreach (string member in members)
             {
                 Member newMember = new Member(member, newBand.Id);
                 newMember.Save();
             }
         }
         List <Band> allBands = Band.GetAll();
         return(View["bands.cshtml", allBands]);
     };
     Post["/venues/new"] = _ => {
         Venue newVenue = new Venue(Request.Form["venue-name"], Request.Form["venue-address"]);
         newVenue.Save();
         List <Venue> allVenues = Venue.GetAll();
         return(View["venues.cshtml", allVenues]);
     };
     Get["/venues/{id}"] = parameters => {
         Dictionary <string, object> model = new Dictionary <string, object> {
         };
         Venue selectedVenue = Venue.Find(parameters.id);
         model.Add("selected-venue", selectedVenue);
         model.Add("venue-bands", selectedVenue.GetBands());
         model.Add("all-bands", Band.GetAll());
         return(View["venue.cshtml", model]);
     };
     Get["/bands/{id}"] = parameters => {
         Dictionary <string, object> model = new Dictionary <string, object> {
         };
         Band selectedBand = Band.Find(parameters.id);
         model.Add("selected-band", selectedBand);
         model.Add("band-venues", selectedBand.GetVenues());
         model.Add("all-venues", Venue.GetAll());
         return(View["band.cshtml", model]);
     };
     Get["/venues/{id}/bands/new"] = parameters => {
         Dictionary <string, object> model = new Dictionary <string, object> {
         };
         Venue selectedVenue = Venue.Find(parameters.id);
         model.Add("selected-venue", selectedVenue);
         model.Add("venue-bands", selectedVenue.GetBands());
         model.Add("all-bands", Band.GetAll());
         return(View["add_band.cshtml", model]);
     };
     Post["/venues/{id}/bands/new"] = parameters => {
         Dictionary <string, object> model = new Dictionary <string, object> {
         };
         Venue selectedVenue = Venue.Find(parameters.id);
         Band  selectedBand  = Band.Find(Request.Form["band-select"]);
         selectedVenue.AddBand(selectedBand);
         model.Add("selected-venue", selectedVenue);
         model.Add("venue-bands", selectedVenue.GetBands());
         model.Add("all-bands", Band.GetAll());
         return(View["venue.cshtml", model]);
     };
     Get["/bands/{id}/venues/new"] = parameters => {
         Dictionary <string, object> model = new Dictionary <string, object> {
         };
         Band selectedBand = Band.Find(parameters.id);
         model.Add("selected-band", selectedBand);
         model.Add("band-venues", selectedBand.GetVenues());
         model.Add("all-venues", Venue.GetAll());
         return(View["add_venue.cshtml", model]);
     };
     Post["/bands/{id}/venues/new"] = parameters => {
         Dictionary <string, object> model = new Dictionary <string, object> {
         };
         Band  selectedBand  = Band.Find(parameters.id);
         Venue selectedVenue = Venue.Find(Request.Form["venue-select"]);
         selectedBand.AddVenue(selectedVenue);
         model.Add("selected-band", selectedBand);
         model.Add("band-venues", selectedBand.GetVenues());
         model.Add("all-venues", Venue.GetAll());
         return(View["band.cshtml", model]);
     };
     Delete["/bands/delete"] = _ => {
         Band.DeleteAll();
         List <Band> allBands = Band.GetAll();
         return(View["bands.cshtml", allBands]);
     };
     Delete["/venues/delete"] = _ => {
         Venue.DeleteAll();
         List <Venue> allVenues = Venue.GetAll();
         return(View["venues.cshtml", allVenues]);
     };
     Get["/venues/{id}/edit"] = parameters => {
         Dictionary <string, object> model = new Dictionary <string, object> {
         };
         Venue selectedVenue = Venue.Find(parameters.id);
         model.Add("selected-venue", selectedVenue);
         model.Add("edit", true);
         return(View["venue_form.cshtml", model]);
     };
     Post["/venues/{id}/edit"] = parameters => {
         Dictionary <string, object> model = new Dictionary <string, object> {
         };
         Venue selectedVenue = Venue.Find(parameters.id);
         selectedVenue.Update(Request.Form["venue-name-edit"], Request.Form["venue-address-edit"]);
         model.Add("selected-venue", selectedVenue);
         model.Add("venue-bands", selectedVenue.GetBands());
         model.Add("all-bands", Band.GetAll());
         return(View["venue.cshtml", model]);
     };
     Get["/venues/{id}/bands/delete"] = parameters => {
         Dictionary <string, object> model = new Dictionary <string, object> {
         };
         Venue selectedVenue = Venue.Find(parameters.id);
         model.Add("selected-venue", selectedVenue);
         model.Add("venue-bands", selectedVenue.GetBands());
         model.Add("all-bands", Band.GetAll());
         model.Add("list-edit", true);
         return(View["venue.cshtml", model]);
     };
     Delete["/venues/{id}/bands/delete"] = parameters => {
         Dictionary <string, object> model = new Dictionary <string, object> {
         };
         Venue  selectedVenue = Venue.Find(parameters.id);
         string bandIds       = Request.Form["band"];
         if (bandIds != null)
         {
             string[] values = bandIds.Split(',');
             foreach (string id in values)
             {
                 Band toDelete = Band.Find(int.Parse(id));
                 selectedVenue.DeleteBandRelationship(toDelete);
             }
         }
         model.Add("selected-venue", selectedVenue);
         model.Add("venue-bands", selectedVenue.GetBands());
         model.Add("all-bands", Band.GetAll());
         return(View["venue.cshtml", model]);
     };
     Delete["/venues/{id}/delete"] = parameters => {
         Venue toDelete = Venue.Find(parameters.id);
         toDelete.Delete();
         List <Venue> allVenues = Venue.GetAll();
         return(View["venues.cshtml", allVenues]);
     };
 }
Beispiel #32
0
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };
            Get["/bands"] = _ => {
                List <Band> allBands = Band.GetAll();
                return(View["bands.cshtml", allBands]);
            };
            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"]);
            };
            Get["/bands/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Band         selectedBand         = Band.Find(parameters.id);//gets current band info
                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]);
            };
            Post["band/add_venue"] = _ => {
                Band  newBand  = Band.Find(Request.Form["band-id"]);
                Venue newVenue = Venue.Find(Request.Form["venue-id"]);
                newBand.AddVenue(newVenue);
                return(View["success.cshtml"]);
            };

            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["/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["venue/add_band"] = _ => {
                Venue newVenue = Venue.Find(Request.Form["venue-id"]);
                Band  newBand  = Band.Find(Request.Form["band-id"]);
                newVenue.AddBand(newBand);
                return(View["success.cshtml"]);
            };

            Get["/venue/{id}/update"] = parameters => {
                Venue selectedVenue = Venue.Find(parameters.id);
                return(View["venue_update.cshtml", selectedVenue]);
            };

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

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

            Post["/bands/delete"] = _ => {
                Band.DeleteAll();
                return(View["success.cshtml"]);
            };
            Post["/venues/delete"] = _ => {
                Venue.DeleteAll();
                return(View["success.cshtml"]);
            };
        }
Beispiel #33
0
 public void Dispose()
 {
     Band.DeleteAll();
     Venue.DeleteAll();
     Venue.DeleteRelationship();
 }
Beispiel #34
0
 public void Dispose()
 {
     Band.DeleteAll();
     Venue.DeleteAll();
 }
Beispiel #35
0
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };
            Get["/venues"] = _ => {
                var allVenues = Venue.GetAll();
                return(View["venues.cshtml", allVenues]);
            };
            Get["/bands"] = _ => {
                var allBands = Band.GetAll();
                return(View ["bands.cshtml", allBands]);
            };
            Get["/venues/new"] = _ => {
                return(View["venues_form.cshtml"]);
            };
            Post["/venues/new"] = _ => {
                Venue newVenue = new Venue(Request.Form["name"]);
                newVenue.Save();
                var allVenues = Venue.GetAll();
                return(View["success.cshtml"]);
            };
            Get["/bands/new"] = _ => {
                return(View["bands_form.cshtml"]);
            };

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

            Get["/shows/new"] = _ => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var allVenues = Venue.GetAll();
                var allBands  = Band.GetAll();
                model.Add("venues", allVenues);
                model.Add("bands", allBands);
                return(View["shows_form.cshtml", model]);
            };

            Post["/shows/new"] = _ => {
                int   venueId       = Request.Form["venue"];
                Venue selectedVenue = Venue.Find(venueId);
                int   bandId        = Request.Form["band"];
                Band  selectedBand  = Band.Find(bandId);
                selectedVenue.AddBand(selectedBand);
                var bands = selectedVenue.GetBands();
                return(View["success.cshtml"]);
            };

            Get["/shows"] = _ => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var allVenues = Venue.GetAll();
                var allBands  = Band.GetAll();
                model.Add("venues", allVenues);
                model.Add("bands", allBands);
                return(View["shows.cshtml", model]);
            };

            Get["/venue/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var selectedVenue = Venue.Find(parameters.id);
                var bands         = selectedVenue.GetBands();
                model.Add("venue", selectedVenue);
                model.Add("bands", bands);
                return(View["venue.cshtml", model]);
            };
            Get["/band/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var selectedBand = Band.Find(parameters.id);
                var venues       = selectedBand.GetVenues();
                model.Add("band", selectedBand);
                model.Add("venues", venues);
                return(View["band.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"]);
            };
        }
Beispiel #36
0
        public HomeModule()
        {
            Get["/"] = _ => {
            Dictionary<string,object> model=Member.AllData("Welcome");
            return View["index.cshtml", model];
              };
              Post["/venue/new"]=_=>{
            Venue newVenue= new Venue(Request.Form["new-venue-name"]);
            newVenue.Save();
            Dictionary<string,object> model=Member.AllData("Welcome");
            return View["index.cshtml", model];
              };
              Delete["/delete/venue/{id}"]=parameters=>{
            Venue newVenue= Venue.Find(parameters.id);
            newVenue.Delete();
            Dictionary<string,object> model=Member.AllData("Welcome");
            return View["index.cshtml", model];
              };
              Patch["/edit/venue/{id}"]=parameters=>{

            Venue newVenue= Venue.Find(parameters.id);
            newVenue.Update(Request.Form["edit-venue-name"]);
            Dictionary<string,object> model=Member.AllData("Welcome");
            return View["index.cshtml", model];
              };

              Post["/venue/addBands/{id}"]=parameters=>{
            Venue newVenue= Venue.Find(parameters.id);
            Band newBand= Band.Find(Request.Form["addBands-id"]);

            newVenue.AddBand(newBand);
            Dictionary<string,object> model=Member.AllData("Welcome");
            return View["index.cshtml", model];
              };

              Get["/view/venue/{id}"]=parameters=>{
            Venue newVenue= Venue.Find(parameters.id);
            List<Band> bandsofVenue=newVenue.GetBands();
            Dictionary<string,object> info = new Dictionary<string,object>{};
            info.Add("venue",newVenue);
            info.Add("bands",bandsofVenue);

            return View["bandsofVenue.cshtml", info];

              };

              Post["/band/new"]=_=>{
            Band newBand= new Band(Request.Form["new-band-name"],Request.Form["new-band-date"]);
            newBand.Save();
            Dictionary<string,object> model=Member.AllData("Welcome");
            return View["index.cshtml", model];
              };
              Delete["/delete/band/{id}"]=parameters=>{
            Band newBand= Band.Find(parameters.id);
            newBand.Delete();
            Dictionary<string,object> model=Member.AllData("Welcome");
            return View["index.cshtml", model];
              };

              Patch["/edit/band/{id}"]=parameters=>{

            Band newBand= Band.Find(parameters.id);
            newBand.Update(Request.Form["edit-band-name"],Request.Form["edit-band-date"]);
            Dictionary<string,object> model=Member.AllData("Welcome");
            return View["index.cshtml", model];
              };

              Post["/band/addVenue/{id}"]=parameters=>{
            Band newBand= Band.Find(parameters.id);
            Venue newVenue= Venue.Find(Request.Form["addVenues-id"]);

            newBand.AddVenue(newVenue);
            Dictionary<string,object> model=Member.AllData("Welcome");
            return View["index.cshtml", model];
              };

              Get["/view/bands/{id}"]=parameters=>{
            Band newBand= Band.Find(parameters.id);
            List<Venue> venueOfBand=newBand.GetVenues();
            Dictionary<string,object> info = new Dictionary<string,object>{};
            info.Add("band",newBand);
            info.Add("venues",venueOfBand);

            return View["venueOfBand.cshtml", info];
              };

              Post["/deleteAll/Venues"]=_=>{
            Venue.DeleteAll();
            Dictionary<string,object> model=Member.AllData("Welcome");
            return View["index.cshtml", model];
              };

            Post["/deleteAll/Bands"]=_=>{
              Band.DeleteAll();
              Dictionary<string,object> model=Member.AllData("Welcome");
              return View["index.cshtml", model];
            };

            Post["/deleteAll"]=_=>{
              Venue.DeleteAll();
              Band.DeleteAll();
              Dictionary<string,object> model=Member.AllData("Welcome");
              return View["index.cshtml", model];
            };
        }
Beispiel #37
0
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };
            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["/bands/new"] = _ => {
                return(View["band_form.cshtml"]);
            };
            Get["/venues/new"] = _ => {
                return(View["venue_form.cshtml"]);
            };
            Post["/bands/new"] = _ => {
                string name = Request.Form["name"];
                name.ToLower();
                string nameTitleCasename = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(name);
                Band   newBand           = new Band(nameTitleCasename, Request.Form["type"]);
                newBand.Save();
                List <Band> AllBands = Band.GetAll();
                return(View["bands.cshtml", AllBands]);
            };
            Post["/venues/new"] = _ => {
                Venue newVenue = new Venue(Request.Form["name"], Request.Form["location"], Request.Form["capacity"]);
                newVenue.Save();
                List <Venue> AllVenues = Venue.GetAll();
                return(View["venues.cshtml", AllVenues]);
            };
            Get["/bands/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var selectedBand = Band.Find(parameters.id);
                var venues       = selectedBand.GetVenue();
                var AllVenues    = Venue.GetAll();
                model.Add("band", selectedBand);
                model.Add("venues", venues);
                model.Add("AllVenues", AllVenues);
                return(View["band.cshtml", model]);
            };
            Get["/venues/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var selectedVenue = Venue.Find(parameters.id);
                var bandsAtVenue  = selectedVenue.GetBand();
                var AllBands      = Band.GetAll();
                model.Add("venue", selectedVenue);
                model.Add("bands", bandsAtVenue);
                model.Add("allBands", AllBands);
                return(View["venue.cshtml", model]);
            };
            Get["bands/{id}/venue"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var AllVenues    = Venue.GetAll();
                var selectedBand = Band.Find(parameters.id);
                model.Add("AllVenues", AllVenues);
                model.Add("band", selectedBand);
                return(View["band_venue_form.cshtml", model]);
            };
            Post["bands/{id}/venue"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Venue selectedVenue = Venue.Find(int.Parse(Request.Form["venue"]));
                var   selectedBand  = Band.Find(parameters.id);
                selectedBand.AddVenue(selectedVenue);
                var venues    = selectedBand.GetVenue();
                var AllVenues = Venue.GetAll();
                model.Add("band", selectedBand);
                model.Add("venues", venues);
                model.Add("AllVenues", AllVenues);
                return(View["band.cshtml", model]);
            };
            Get["venues/{id}/band"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var AllBands      = Band.GetAll();
                var selectedVenue = Venue.Find(parameters.id);
                model.Add("AllBands", AllBands);
                model.Add("venue", selectedVenue);
                return(View["venue_band_form.cshtml", model]);
            };
            Post["venues/{id}/band"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Band selectedBand  = Band.Find(int.Parse(Request.Form["band"]));
                var  selectedVenue = Venue.Find(parameters.id);
                selectedVenue.AddBand(selectedBand);
                var bands    = selectedVenue.GetBand();
                var AllBands = Band.GetAll();
                model.Add("venue", selectedVenue);
                model.Add("bands", bands);
                model.Add("AllBands", AllBands);
                return(View["venue.cshtml", model]);
            };
            Get["venues/edit/{id}"] = parameters => {
                Venue selectedVenue = Venue.Find(parameters.id);
                return(View["venue_edit.cshtml", selectedVenue]);
            };
            Patch["/venues/edit/{id}"] = parameters => {
                Venue SelectedVenue = Venue.Find(parameters.id);
                SelectedVenue.Update(Request.Form["name"], Request.Form["location"], int.Parse(Request.Form["capacity"]));
                return(View["success.cshtml"]);
            };
            Get["venues/delete/{id}"] = parameters => {
                Venue SelectedVenue = Venue.Find(parameters.id);
                return(View["venue_delete.cshtml", SelectedVenue]);
            };
            Delete["venues/delete/{id}"] = parameters => {
                Venue SelectedVenue = Venue.Find(parameters.id);
                SelectedVenue.Delete();
                return(View["success.cshtml"]);
            };

            Post["/bands/clear"] = _ => {
                Band.DeleteAll();
                List <Band> AllBand = Band.GetAll();
                return(View["bands.cshtml", AllBand]);
            };
            Post["/venues/clear"] = _ => {
                Venue.DeleteAll();
                List <Venue> AllVenue = Venue.GetAll();
                return(View["venues.cshtml", AllVenue]);
            };
        }
Beispiel #38
0
 public void Test_Save_SavesToDatabase()
 {
     //Arrange
       Venue testVenue = new Venue("The Crocodile");
       //Act
       testVenue.Save();
       List<Venue> result = Venue.GetAll();
       List<Venue> testList = new List<Venue>{testVenue};
       //Assert
       Assert.Equal(testList, result);
 }
Beispiel #39
0
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };

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

            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"]);
            };

            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]);
            };

            Post["/bands/delete"] = _ => {
                Band.DeleteAll();
                return(View["cleared.cshtml"]);
            };
            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["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.AddVenue(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.AddBand(band);
                return(View["success.cshtml"]);
            };

            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"]);
            };

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

            Get["/contact"] = _ => {
                return(View["contact.cshtml"]);
            };
        }
 public HomeModule()
 {
     Get["/"] = _ => {
         return(View["index.cshtml"]);
     };
     Get["/bands"] = _ => {
         List <Band> allBands = Band.GetAll();
         return(View["bands.cshtml", allBands]);
     };
     Get["/band/new"] = _ => {
         return(View["new_band.cshtml"]);
     };
     Post["/band/new"] = _ => {
         Band newBand = new Band(Request.Form["band-name"]);
         newBand.Save();
         return(View["new_band.cshtml", newBand]);
     };
     Get["/venues"] = _ => {
         List <Venue> allVenues = Venue.GetAll();
         return(View["venues.cshtml", allVenues]);
     };
     Get["/venue/new"] = _ => {
         return(View["new_venue.cshtml"]);
     };
     Post["/venue/new"] = _ => {
         Venue newVenue = new Venue(Request.Form["venue-name"]);
         newVenue.Save();
         return(View["new_venue.cshtml", newVenue]);
     };
     Get["/band/{id}"] = parameters => {
         Dictionary <string, object> model = new Dictionary <string, object>();
         Band         foundBand            = Band.Find(parameters.id);
         List <Venue> venues    = foundBand.GetVenues();
         List <Venue> allVenues = Venue.GetAll();
         model.Add("current-band", foundBand);
         model.Add("venues-in-band", venues);
         model.Add("all-venues", allVenues);
         return(View["band.cshtml", model]);
     };
     Post["/band/add_venue"] = _ => {
         Band  band  = Band.Find(Request.Form["band-id"]);
         Venue venue = Venue.Find(Request.Form["venue-id"]);
         band.AddVenue(venue);
         return(View["success.cshtml"]);
     };
     Get["/venue/{id}"] = parameters => {
         Dictionary <string, object> model = new Dictionary <string, object>();
         Venue       foundVenue            = Venue.Find(parameters.id);
         List <Band> bands    = foundVenue.GetBands();
         List <Band> allBands = Band.GetAll();
         model.Add("current-venue", foundVenue);
         model.Add("bands-in-venue", bands);
         model.Add("all-bands", allBands);
         return(View["venue.cshtml", model]);
     };
     Post["/venue/add_band"] = _ => {
         Venue newVenue = Venue.Find(Request.Form["venue-id"]);
         Band  newBand  = Band.Find(Request.Form["band-id"]);
         newVenue.AddBand(newBand);
         return(View["success.cshtml"]);
     };
     Get["/venue/delete/{id}"] = parameters => {
         Venue newVenue = Venue.Find(parameters.id);
         return(View["venue_delete.cshtml", newVenue]);
     };
     Delete["/venue/delete/{id}"] = parameters => {
         Venue selectedVenue = Venue.Find(parameters.id);
         selectedVenue.Delete();
         return(View["success.cshtml"]);
     };
     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"]);
     };
 }
Beispiel #41
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]);
            };

            Post["/venue/new"] = _ => {
                Venue newVenue = new Venue(Request.Form["name"]);
                newVenue.Save();
                List <Venue> AllVenues = Venue.GetAll();
                return(View["index.cshtml", AllVenues]);
            };

            Post["/band/new"] = _ => {
                Band newBand = new Band(Request.Form["name"]);
                newBand.Save();
                List <Band> AllBands = Band.GetAll();
                return(View["bands.cshtml", AllBands]);
            };

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

            Get["/band/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                var          SelectedBand         = Band.Find(parameters.id);
                List <Venue> BandVenues           = SelectedBand.GetVenues();
                model.Add("band", SelectedBand);
                model.Add("venues", BandVenues);
                return(View["band.cshtml", model]);
            };

            Delete["/venue/delete/{id}"] = parameters => {
                Venue SelectedVenue = Venue.Find(parameters.id);
                SelectedVenue.Delete();
                List <Venue> AllVenues = Venue.GetAll();
                return(View["index.cshtml", AllVenues]);
            };

            Get["/venue/edit/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                var         SelectedVenue         = Venue.Find(parameters.id);
                List <Band> AllBands = Band.GetAll();
                model.Add("venue", SelectedVenue);
                model.Add("bands", AllBands);
                return(View["venue_edit.cshtml", model]);
            };

            Get["/band/edit/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                var          SelectedBand         = Band.Find(parameters.id);
                List <Venue> AllVenues            = Venue.GetAll();
                model.Add("band", SelectedBand);
                model.Add("venues", AllVenues);
                return(View["band_edit.cshtml", model]);
            };

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

            Post["/venue/add_band"] = _ => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                var SelectedVenue = Venue.Find(Request.Form["venue-id"]);
                var SelectedBand  = Band.Find(Request.Form["band-id"]);
                SelectedVenue.AddBand(SelectedBand);
                List <Band> VenueBands = SelectedVenue.GetBands();
                model.Add("venue", SelectedVenue);
                model.Add("bands", VenueBands);
                return(View["venue.cshtml", model]);
            };

            Post["/band/add_venue"] = _ => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                var SelectedVenue = Venue.Find(Request.Form["venue-id"]);
                var SelectedBand  = Band.Find(Request.Form["band-id"]);
                SelectedBand.AddVenue(SelectedVenue);
                List <Venue> BandVenues = SelectedBand.GetVenues();
                model.Add("band", SelectedBand);
                model.Add("venues", BandVenues);
                return(View["band.cshtml", model]);
            };
        }
Beispiel #42
0
        public HomeModule()
        {
            // Take you to the homepage
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };

            // Take you to the venues page
            Get["/venues"] = _ => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                List <Venue> allVenues            = Venue.GetAllVenues();
                model.Add("venue", allVenues);
                return(View["venues.cshtml", model]);
            };
            // Post for adding a new venue
            Post["/venues"] = _ => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Venue newVenue = new Venue(Request.Form["venue"]);
                newVenue.Save();
                List <Venue> allVenues = Venue.GetAllVenues();
                model.Add("venue", allVenues);
                return(View["venues.cshtml", model]);
            };
            // Take you to an individual venue page
            Get["/venues/{id}/{name}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Venue       selectedVenue         = Venue.Find(parameters.id);
                List <Band> allBands = Band.GetAllBands();
                model.Add("venue", selectedVenue);
                model.Add("bands", allBands);
                return(View["venue.cshtml", model]);
            };
            // Post a new band to a venue
            Post["/venues/{id}/{name}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Band  newBand      = new Band(Request.Form["add-band"]);
                Venue currentVenue = Venue.Find(Request.Form["venue-id"]);
                newBand.Save();
                List <Venue> allVenues = Venue.GetAllVenues();
                currentVenue.AddBand(newBand);
                List <Band> allBands = Band.GetAllBands();
                model.Add("venue", currentVenue);
                model.Add("bands", allBands);
                return(View["venue.cshtml", model]);
            };

            // Take you to the bands page
            Get["/bands"] = _ => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                List <Band> allBands = Band.GetAllBands();
                model.Add("bands", allBands);
                return(View["bands.cshtml", model]);
            };
            // Take you to an individual band page
            Get["/bands/{id}/{name}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Band         selectedBand         = Band.Find(parameters.id);
                List <Venue> allVenues            = Venue.GetAllVenues();
                model.Add("band", selectedBand);
                model.Add("venues", allVenues);
                return(View["band.cshtml", model]);
            };

            // Take you to the page to edit a venue
            Get["/venues/{id}/{name}/edit"] = parameters => {
                Venue selectedVenue = Venue.Find(parameters.id);
                return(View["edit_venue.cshtml", selectedVenue]);
            };

            // Edit a venue
            Patch["/venue/{id}/updated"] = parameters => {
                Venue selectedVenue = Venue.Find(parameters.id);
                selectedVenue.Update(Request.Form["edit-venue"]);
                return(View["venue_updated.cshtml", selectedVenue]);
            };

            // take you to page to delete a venue
            Get["venue/{id}/{name}/delete"] = parameters => {
                Venue selectedVenue = Venue.Find(parameters.id);
                return(View["delete_venue.cshtml", selectedVenue]);
            };
            // Delete a venue
            Delete["/venue/{id}/{name}/deleted"] = parameters => {
                Venue specificVenue = Venue.Find(parameters.id);
                specificVenue.Delete();
                return(View["deleted.cshtml"]);
            };

            // take you to page to delete a band
            Get["band/{id}/delete"] = parameters => {
                Band selectedBand = Band.Find(parameters.id);
                return(View["delete_band.cshtml", selectedBand]);
            };
            // Delete a band
            Delete["/band/{id}/deleted"] = parameters => {
                Band specificBand = Band.Find(parameters.id);
                specificBand.Delete();
                return(View["deleted.cshtml"]);
            };
        }
Beispiel #43
0
        public void Test1_TestsEmptyAtFirst()
        {
            int result = Venue.GetAll().Count;

            Assert.Equal(0, result);
        }
Beispiel #44
0
 public void Test_GetBands_ReturnsAllVenueBands()
 {
     //Arrange
       Venue testVenue = new Venue("The Catwalk");
       testVenue.Save();
       Band testBand1 = new Band("The LoudMouths");
       testBand1.Save();
       Band testBand2 = new Band("The NoiseMakers");
       testBand2.Save();
       List<Band> testList = new List<Band> {testBand1};
       //Act
       testVenue.AddBand(testBand1);
       List<Band> savedBands = testVenue.GetBands();
       //Assert
       Assert.Equal(testList, savedBands);
 }
 public HomeModule()
 {
     Get["/"] = _ => {
         Dictionary <string, object> model = new Dictionary <string, object>();
         List <Band>  allBands             = Band.GetAll();
         List <Venue> allVenues            = Venue.GetAll();
         model.Add("bands", allBands);
         model.Add("venues", allVenues);
         return(View["index.cshtml", model]);
     };
     Get["/band/new"] = _ => {
         return(View["new-band-form.cshtml"]);
     };
     Get["/venue/new"] = _ => {
         return(View["new-venue-form.cshtml"]);
     };
     Post["/band/new"] = _ => {
         Band newBand = new Band(Request.Form["bandName"]);
         newBand.Save();
         return(View["created.cshtml", newBand]);
     };
     Post["/venue/new"] = _ => {
         Venue newVenue = new Venue(Request.Form["venueName"]);
         newVenue.Save();
         return(View["created.cshtml", newVenue]);
     };
     Get["/band/{id}"] = parameters => {
         Band currentBand = Band.Find(parameters.id);
         Dictionary <string, object> model = new Dictionary <string, object>();
         model.Add("band", currentBand);
         model.Add("bandVenues", currentBand.GetVenues());
         model.Add("venues", Venue.GetAll());
         return(View["band.cshtml", model]);
     };
     Post["/band/{id}/add-venue"] = parameters => {
         Band  currentBand  = Band.Find(parameters.id);
         Venue currentVenue = Venue.Find(Request.Form["venueId"]);
         currentBand.AddVenue(Request.Form["venueId"]);
         Dictionary <string, object> model = new Dictionary <string, object>();
         model.Add("band", currentBand);
         model.Add("venue", currentVenue);
         return(View["saved.cshtml", model]);
     };
     Get["/venue/{id}"] = parameters => {
         Venue currentVenue = Venue.Find(parameters.id);
         Dictionary <string, object> model = new Dictionary <string, object>();
         model.Add("venue", currentVenue);
         model.Add("venueBands", currentVenue.GetBands());
         model.Add("bands", Band.GetAll());
         return(View["venue.cshtml", model]);
     };
     Post["/venue/{id}/add-band"] = parameters => {
         Venue currentVenue = Venue.Find(parameters.id);
         Band  currentBand  = Band.Find(Request.Form["bandId"]);
         currentVenue.AddBand(Request.Form["bandId"]);
         Dictionary <string, object> model = new Dictionary <string, object>();
         model.Add("band", currentBand);
         model.Add("venue", currentVenue);
         return(View["saved.cshtml", model]);
     };
     Get["/band/{id}/edit"] = parameters => {
         Band currentBand = Band.Find(parameters.id);
         return(View["edit-band-form.cshtml", currentBand]);
     };
     Get["/venue/{id}/edit"] = parameters => {
         Venue currentVenue = Venue.Find(parameters.id);
         return(View["edit-venue-form.cshtml", currentVenue]);
     };
     Patch["/band/{id}"] = parameters => {
         Band currentBand = Band.Find(parameters.id);
         currentBand.Edit(Request.Form["newName"]);
         return(View["edit-success.cshtml", currentBand]);
     };
     Patch["/venue/{id}"] = parameters => {
         Venue currentVenue = Venue.Find(parameters.id);
         currentVenue.Edit(Request.Form["newName"]);
         return(View["edit-success.cshtml", currentVenue]);
     };
     Delete["/band/{id}"] = parameters => {
         Band currentBand = Band.Find(parameters.id);
         currentBand.Delete();
         return(View["delete-success.cshtml", currentBand]);
     };
     Delete["/venue/{id}"] = parameters => {
         Venue currentVenue = Venue.Find(parameters.id);
         currentVenue.Delete();
         return(View["delete-success.cshtml", currentVenue]);
     };
 }
Beispiel #46
0
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };

            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["venue_form.cshtml"]);
            };

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

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

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

            Get["/band/{id}/venues/add"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> ();
                Band         selectedBand         = Band.Find(parameters.id);
                List <Venue> currentVenues        = selectedBand.GetVenues();
                List <Venue> allVenues            = Venue.GetAll();

                List <Venue> availableVenues = new List <Venue> {
                };
                foreach (Venue venue in allVenues)
                {
                    // If a venue is already in the band it will return an index of 0 or above.
                    if (currentVenues.IndexOf(venue) < 0)
                    {
                        availableVenues.Add(venue);
                    }
                }
                model.Add("band", selectedBand);
                model.Add("available-venues", availableVenues);
                return(View["AddVenueToBand.cshtml", model]);
            };

            Get["/venues/{id}/bands/add"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> ();
                Venue       selectedVenue         = Venue.Find(parameters.id);
                List <Band> currentBands          = selectedVenue.GetBands();
                List <Band> allBands = Band.GetAll();

                List <Band> availableBands = new List <Band> {
                };
                foreach (Band band in allBands)
                {
                    // If the band is already enrolled in a venue it will return an index of 0 or above.
                    if (currentBands.IndexOf(band) < 0)
                    {
                        availableBands.Add(band);
                    }
                }
                model.Add("venue", selectedVenue);
                model.Add("available-bands", availableBands);
                return(View["AddBandToVenue.cshtml", model]);
            };

            Get["/venue/{venue_id}"] = parameters => {
                Venue selectedVenue = Venue.Find(parameters.venue_id);
                return(View["venue.cshtml", selectedVenue]);
            };

            Get["/band/{band_id}"] = parameters => {
                Band selectedBand = Band.Find(parameters.band_id);
                return(View["band.cshtml", selectedBand]);
            };

            Post["/band/{id}/venues/added"] = parameters => {
                int   venueId       = int.Parse(Request.Form["venue-id"]);
                Venue selectedVenue = Venue.Find(venueId);

                Band selectedBand = Band.Find(parameters.id);
                selectedBand.AddVenue(selectedVenue);

                return(View["venue_added.cshtml", selectedBand]);
            };

            Post["/venue/{id}/bands/added"] = parameters => {
                int  bandId       = int.Parse(Request.Form["band-id"]);
                Band selectedBand = Band.Find(bandId);

                Venue selectedVenue = Venue.Find(parameters.id);
                selectedVenue.AddBand(selectedBand);

                return(View["band_added.cshtml", selectedVenue]);
            };

            Get["/venues/{id}/update"] = parameters => {
                Venue selectedVenue = Venue.Find(parameters.id);

                return(View["update.cshtml", selectedVenue]);
            };

            Patch["/venues/{id}/update"] = parameters => {
                Venue selectedVenue = Venue.Find(parameters.id);

                string newName    = Request.Form["new-name"];
                string newAddress = Request.Form["new-address"];

                selectedVenue.Update(newName, newAddress);

                return(View["success.cshtml", selectedVenue]);
            };

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

            Delete["/venues/{id}/delete"] = parameters => {
                Venue selectedVenue = Venue.Find(parameters.id);

                selectedVenue.Delete();

                return(View["deleted.cshtml"]);
            };
        }
Beispiel #47
0
        public HomeModule()
        {
            Get["/"] = _ => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                model.Add("allVenues", Venue.GetAll());
                model.Add("allBands", Band.GetAll());
                return(View["index.cshtml", model]);
            };
            Get["/venues/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Venue venue = Venue.Find(parameters.id);
                model.Add("allVenues", Venue.GetAll());
                model.Add("venue", venue);
                model.Add("venues-bands", venue.GetBands());
                model.Add("allBands", Band.GetAll());
                return(View["index.cshtml", model]);
            };
            Get["/venues/{venId}/bands/{bandId}/events"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Venue selectedVenue = Venue.Find(parameters.venId);
                Band  selectedBand  = Band.Find(parameters.bandId);
                model.Add("venue", selectedVenue);
                model.Add("allVenues", Venue.GetAll());
                model.Add("show-venue", selectedVenue);
                model.Add("venues-bands", selectedVenue.GetBands());
                model.Add("events", selectedVenue.GetEvents(selectedBand));
                model.Add("allBands", Band.GetAll());
                return(View["index.cshtml", model]);
            };
            Get["/venues/new"] = _ => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                model.Add("bands", Band.GetAll());
                model.Add("add-venue", null);
                return(View["form.cshtml", model]);
            };
            Post["/venues/new"] = _ => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                model.Add("bands", Band.GetAll());
                Venue newVenue = new Venue(Request.Form["name"], Request.Form["capacity"]);
                newVenue.Save();
                if (Request.Form["band"] != "")
                {
                    Band selectedBand = Band.Find(Request.Form["band"]);
                    newVenue.AddBand(selectedBand, Request.Form["date"]);
                    model.Add("band", Band.Find(Request.Form["band"]));
                }
                model.Add("new-venue", newVenue);
                return(View["form.cshtml", model]);
            };
            Get["/venues/{id}/update"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Venue selectedVenue = Venue.Find(parameters.id);
                model.Add("venue", selectedVenue);
                model.Add("bands", selectedVenue.GetBands());
                model.Add("show", "update-form");
                model.Add("otherBands", selectedVenue.GetOtherBands());

                return(View["update_form.cshtml", model]);
            };
            Patch["/venues/{id}/update"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Venue  selectedVenue = Venue.Find(parameters.id);
                string bands         = Request.Form["band"];
                if (bands != null)
                {
                    string[] values = bands.Split(',');
                    foreach (string bandId in values)
                    {
                        selectedVenue.DeleteBandRelationship(Band.Find(int.Parse(bandId)));
                    }
                }
                selectedVenue.Update(Request.Form["name"]);
                model.Add("venue", selectedVenue);
                model.Add("bands", selectedVenue.GetBands());
                model.Add("show", "update-info");
                return(View ["update_form.cshtml", model]);
            };
            Get["/bands/new"] = _ => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                model.Add("new-band", null);
                model.Add("venues", Venue.GetAll());
                return(View["form.cshtml", model]);
            };
            Post["/bands/new"] = _ => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Band newBand = new Band(Request.Form["name"]);
                newBand.Save();
                if (Request.Form["venue-selected"] != "")
                {
                    Venue selectedVenue = Venue.Find(Request.Form["venue-choose"]);
                    newBand.AddVenue(selectedVenue, Request.Form["date"]);
                    model.Add("venue-selected", selectedVenue);
                }
                model.Add("allVenues", Venue.GetAll());
                model.Add("allBands", Band.GetAll());
                return(View["index.cshtml", model]);
            };
            Delete["/venues/{id}/delete"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Venue selectedVenue = Venue.Find(parameters.id);
                selectedVenue.DeleteSingleVenue();
                string name = selectedVenue.Name;
                model.Add("allVenues", Venue.GetAll());
                model.Add("allBands", Band.GetAll());
                model.Add("delete-confirm", name);
                return(View["index.cshtml", model]);
            };
        }
Beispiel #48
0
        // a method to get all Venue records
        public static List<Venue> GetAll()
        {
            SqlConnection conn = DB.Connection();
              conn.Open();

              SqlCommand cmd = new SqlCommand("SELECT * FROM venues ORDER BY name;", conn);

              SqlDataReader rdr = cmd.ExecuteReader();
              List<Venue> allVenues = new List<Venue>{};
              while(rdr.Read())
              {
            int id = rdr.GetInt32(0);
            string name = rdr.GetString(1);
            Venue newVenue = new Venue(name, id);
            allVenues.Add(newVenue);
              }
              if (rdr !=null)
              {
            rdr.Close();
              }
              if (conn !=null)
              {
            conn.Close();
              }
              return allVenues;
        }
Beispiel #49
0
 public void Dispose()
 {
     Venue.DeleteAll();
 }
        public void AddVenue(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();
              }
        }
Beispiel #51
0
        public HomeModule()
        {
            Get["/"] = _ => View["index.cshtml"];

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

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

            Get["/bands/new"] = _ => {
                List <Venue> AllVenues = Venue.GetAll();
                return(View["bands_form.cshtml", AllVenues]);
            };
            Post["/bands/new"] = _ => {
                Band newBand = new Band(Request.Form["band-name"], Request.Form["band-genre"], Request.Form["band-song"]);
                newBand.Save();
                return(View["bands.cshtml", Band.GetAll()]);
            };

            Get["/venues/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var         SelectedVenue         = Venue.Find(parameters.id);
                var         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]);
            };
            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]);
            };

            Post["/band/add_venue"] = _ => {
                Venue venue = Venue.Find(Request.Form["venue-id"]);
                Band  band  = Band.Find(Request.Form["band-id"]);
                band.AddVenue(venue);
                return(View["venue-list.cshtml", band.GetVenues()]);
            };
            Post["/venue/add_band"] = _ => {
                Venue venue = Venue.Find(Request.Form["venue-id"]);
                Band  band  = Band.Find(Request.Form["band-id"]);
                venue.AddBand(band);
                return(View["band-list.cshtml", venue.GetBands()]);
            };

            Patch["/venue/edit/{id}"] = parameters => {
                Venue SelectedVenue = Venue.Find(parameters.id);
                SelectedVenue.UpdateVenues(Request.Form["new-venue-name"]);
                return(View["venues.cshtml", Venue.GetAll()]);
            };

            Get["/bands/detail/{id}"] = parameters =>
            {
                Band band = Band.Find(parameters.id);
                return(View["band-detail.cshtml", band]);
            };

            Delete["/venues/{id}"] = parameters =>
            {
                Venue targetVenue = Venue.Find(parameters.id);
                targetVenue.Delete();
                return(View["venues.cshtml", Venue.GetAll()]);
            };
            Delete["/bands/{id}"] = parameters =>
            {
                Band targetBand = Band.Find(parameters.id);
                targetBand.Delete();
                return(View["bands.cshtml", Band.GetAll()]);
            };

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