public static Band Find(int Id) { SqlConnection conn = DB.Connection(); conn.Open(); SqlDataReader rdr; SqlCommand cmd = new SqlCommand("SELECT * FROM bands WHERE id = @BandId;", conn); SqlParameter bandIdParameter = new SqlParameter(); bandIdParameter.ParameterName = "@BandId"; bandIdParameter.Value = Id.ToString(); cmd.Parameters.Add(bandIdParameter); rdr = cmd.ExecuteReader(); Band foundBand = null; while(rdr.Read()) { int foundId = rdr.GetInt32(0); string foundName = rdr.GetString(1); foundBand = new Band(foundName, foundId); } if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return foundBand; }
public void Test_Save_Find_Delete() { Band testBand = new Band("Pazz", "Jeff and the Baboons"); testBand.Save(); testBand.Delete(new string[] {"performances"}, new string[] {"band_id"}); Assert.Equal(null, Band.Find(testBand.id)); }
public static List<Band> GetAll() { List<Band> AllBands = new List<Band>{}; SqlConnection conn = DB.Connection(); conn.Open(); SqlDataReader rdr; SqlCommand cmd = new SqlCommand("SELECT * FROM bands;", conn); rdr = cmd.ExecuteReader(); while(rdr.Read()) { int bandId = rdr.GetInt32(0); string bandName = rdr.GetString(1); Band newBand = new Band(bandName, bandId); AllBands.Add(newBand); } if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return AllBands; }
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()]; }; }
public void Test_Equal_ReturnsTrueForSameName() { //Arrange, Act Band firstBand = new Band("The LoudMouths"); Band secondBand = new Band("The LoudMouths"); //Assert Assert.Equal(firstBand, secondBand); }
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 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]; }; }
public void Test_Find_FindsBandInDatabase() { Band testBand = new Band("Frets on Fire", 0); testBand.Save(); Band foundBand = Band.Find(testBand.GetId()); Assert.Equal(testBand, foundBand); }
public void Test_Save_SavesToDatabase() { Band testBand = new Band("Frets on Fire", 0); testBand.Save(); List<Band> testList = new List<Band>{testBand}; List<Band> result = Band.GetAll(); Assert.Equal(testList, result); }
public void Test_Find_FindsBandInDatabase() { //Arrange Band testBand = new Band("The NoiseMakers"); testBand.Save(); //Act Band foundBand = Band.Find(testBand.GetId()); //Assert Assert.Equal(testBand, foundBand); }
public void Test_Save_AssignsIdToBandObject() { //Arrange Band testBand = new Band("The Rough Nighters"); testBand.Save(); //Act Band savedBand = Band.GetAll()[0]; int result = savedBand.GetId(); int testId = testBand.GetId(); //Assert Assert.Equal(testId, result); }
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); }
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); }
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); }
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); }
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); }
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); }
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]; }; }
public void Test_GetBands_ReturnAllVenueBands() { Venue testVenue = new Venue("place"); testVenue.Save(); DateTime testTime = new DateTime(2016, 1, 1); Band testBand1= new Band("A",testTime); testBand1.Save(); Band testBand2 = new Band("C",testTime); testBand2.Save(); testVenue.AddBand(testBand1); List<Band> savedBands = testVenue.GetBands(); List<Band> testList= new List<Band>{testBand1}; Assert.Equal(testList,savedBands); }
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"]); }; }
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); }
// methods to interact with the Band class // a method to add a new link between a band and venue instance public void AddBand(Band newBand) { SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO events (venue_id, band_id) VALUES (@VenueId, @BandId);", conn); SqlParameter venueIdParameter = new SqlParameter(); venueIdParameter.ParameterName = "@VenueId"; venueIdParameter.Value = this.GetId(); cmd.Parameters.Add(venueIdParameter); SqlParameter bandIdParameter = new SqlParameter(); bandIdParameter.ParameterName = "@BandId"; bandIdParameter.Value = newBand.GetId(); cmd.Parameters.Add(bandIdParameter); cmd.ExecuteNonQuery(); if (conn != null) { conn.Close(); } }
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 void GetAll_DatabaseEmptyAtFirst_Empty() { int result = Band.GetAll().Count; Assert.Equal(0, result); }
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]); }; }
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]); }; }
public List<Band> GetBands() { SqlConnection conn = DB.Connection(); conn.Open(); SqlDataReader rdr; SqlCommand cmd = new SqlCommand("SELECT bands.* FROM bands JOIN venues_bands ON(bands.id = venues_bands.band_id) JOIN venues ON(venues_bands.venue_id = venues.id) WHERE venues.id = @VenueId;", conn); SqlParameter venueIdParameter = new SqlParameter(); venueIdParameter.ParameterName = "@VenueId"; venueIdParameter.Value = this.GetId(); cmd.Parameters.Add(venueIdParameter); rdr = cmd.ExecuteReader(); List<Band> allBands = new List<Band> {}; while (rdr.Read()) { int thisBandId = rdr.GetInt32(0); string bandName = rdr.GetString(1); Band foundBand = new Band(bandName, thisBandId); allBands.Add(foundBand); } if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return allBands; }
public HomeModule() { Get["/"] = _ => { return View["index.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 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"]; }; Get["/bands"] = _ => { List<Band> AllBands = Band.GetAll(); return View["bands.cshtml", AllBands]; }; 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"]); 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["/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"]; }; }
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"]); }; }
// a method to delete records between tests public void Dispose() { Band.DeleteAll(); Venue.DeleteAll(); }
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"]); }; }
public void GetAll_BandEmptyAtFirst_true() { int result = Band.GetAll().Count; Assert.Equal(0, result); }
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["/"] = _ => { 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]); }; //Create a new band. 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"]); }; //Create a new venue. 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}"] = param => { Dictionary <string, object> model = new Dictionary <string, object>(); Venue SelectedVenue = Venue.Find(param.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]); }; Get["bands/{id}"] = param => { Dictionary <string, object> model = new Dictionary <string, object>(); Band SelectedBand = Band.Find(param.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["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["venues/delete/{id}"] = param => { Venue SelectedVenue = Venue.Find(param.id); return(View["venues_delete.cshtml", SelectedVenue]); }; Delete["venues/delete/{id}"] = param => { Venue SelectedVenue = Venue.Find(param.id); SelectedVenue.Delete(); return(View["success.cshtml"]); }; Get["/venues/edit/{id}"] = param => { Venue SelectedVenue = Venue.Find(param.id); return(View["venues_edit.cshtml", SelectedVenue]); }; Post["/venues/edit/{id}"] = param => { Venue SelectedVenue = Venue.Find(param.id); return(View["success.cshtml", SelectedVenue]); }; Patch["/venues/edit/{id}"] = param => { Venue SelectedVenue = Venue.Find(param.id); SelectedVenue.Update(Request.Form["edit-venue-name"]); return(View["success.cshtml"]); }; }
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]); }; }
public void Test_Save_SavesBandToDatabase() { //Arrange Band testBand = new Band("The LoudMouths"); testBand.Save(); List<Band> testList = new List<Band>{testBand}; //Act List<Band> resultList = Band.GetAll(); //Assert Assert.Equal(testList, resultList); }
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"]); }; }
public void Test_AddBand_AddsBandToVenue() { //Arrange Venue testVenue = new Venue("A"); testVenue.Save(); DateTime testTime = new DateTime(2016, 1, 1); Band testBand = new Band("A",testTime); testBand.Save(); Band testBand2 = new Band("B",testTime); testBand2.Save(); //Act testVenue.AddBand(testBand); testVenue.AddBand(testBand2); List<Band> result = testVenue.GetBands(); List<Band> testList = new List<Band> {testBand, testBand2}; Assert.Equal(testList, result); }
// a method to get all band instances associated with a venue instance public List<Band> GetBands() { SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT bands.* FROM venues JOIN events ON (venues.id = events.venue_id) JOIN bands ON (events.band_id = bands.id) WHERE venues.id = @VenueId ORDER BY name;", conn); SqlParameter VenueIdParameter = new SqlParameter(); VenueIdParameter.ParameterName = "@VenueId"; VenueIdParameter.Value = this.GetId().ToString(); cmd.Parameters.Add(VenueIdParameter); SqlDataReader rdr = cmd.ExecuteReader(); List<Band> bands = new List<Band>{}; while(rdr.Read()) { int bandId = rdr.GetInt32(0); string bandName = rdr.GetString(1); Band newBand = new Band(bandName, bandId); bands.Add(newBand); } if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return bands; }
public void Test_Delete_DeletesVenueAssociationsFromDatabase() { //Arrange DateTime testTime = new DateTime(2016, 1, 1); Band testBand = new Band("A",testTime); testBand.Save(); string testName = "Home stuff"; Venue testVenue = new Venue(testName); testVenue.Save(); //Act testVenue.AddBand(testBand); testVenue.Delete(); List<Venue> resultBandVenues = testBand.GetVenues(); List<Venue> testBandVenues = new List<Venue> {}; List<Band> resultsBands= Band.GetAll(); List<Band> testBands= new List<Band>{testBand}; //Assert Assert.Equal(testBandVenues, resultBandVenues); Assert.Equal(testBands, resultsBands); }
public HomeModule() { Get["/"] = _ => { return(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-description"]); newVenue.Save(); newVenue.Update(newVenue.ForceCapital(newVenue.GetName())); 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(); newBand.Update(newBand.ForceCapital(newBand.GetName())); 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]); }; 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["venue/add_band"] = _ => { Band band = Band.Find(Request.Form["band-id"]); Venue venue = Venue.Find(Request.Form["venue-id"]); venue.AddBand(band); return(View["success.cshtml"]); }; 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["venues/update/{id}"] = parameters => { Venue foundVenue = Venue.Find(parameters.id); return(View["venue_update.cshtml", foundVenue]); }; Patch["venues/update/{id}"] = parameters => { Venue foundVenue = Venue.Find(parameters.id); foundVenue.Update(Request.Form["new-description"]); return(View["success.cshtml"]); }; Get["bands/update/{id}"] = parameters => { Band foundBand = Band.Find(parameters.id); return(View["band_update.cshtml", foundBand]); }; Patch["bands/update/{id}"] = parameters => { Band foundBand = Band.Find(parameters.id); foundBand.Update(Request.Form["new-description"]); return(View["success.cshtml"]); }; Delete["band/delete/{id}"] = parameters => { Band foundBand = Band.Find(parameters.id); foundBand.Delete(); return(View["success.cshtml"]); }; Delete["venue/delete/{id}"] = parameters => { Venue foundVenue = Venue.Find(parameters.id); foundVenue.Delete(); return(View["success.cshtml"]); }; Delete["venues/delete_all"] = _ => { Venue.DeleteAll(); return(View["success.cshtml"]); }; }
public void Dispose() { Band.DeleteAll(); Venue.DeleteAll(); Venue.DeleteRelationship(); }