// GET: Ensemble/Musicians //Given an ensemble id, return a list of all musicians who play in that ensemble. public IActionResult Musicians(int id) { //Nested query. Select any musician whose id is in an ensemble player record where the ensemble id for that record matches the id supplied. IEnumerable <Musician> musicians = from musician in _context.Musician where (from ensemblePlayer in _context.EnsemblePlayers where ensemblePlayer.EnsembleId == id select ensemblePlayer).Any(e => e.MusicianId == musician.MusicianId) select musician; Ensemble ensemble = _context.Ensemble.Find(id); EnsembleAndMusicians eAndM = new EnsembleAndMusicians(ensemble, musicians); return(View(eAndM)); }
// GET: Musician //Index page, if no id is given, the page will simply display all musicians. //If an id is given, the page will include a button to add any player to the //ensemble, and a button to goto the details page for the ensemble. public async Task <IActionResult> Index(int?id) { EnsembleAndMusicians eAndM; if (id == null) { eAndM = new EnsembleAndMusicians(null, _context.Musician); } else { Ensemble ensemble = await _context.Ensemble.FindAsync(id); if (ensemble == null) { return(NotFound()); } eAndM = new EnsembleAndMusicians(ensemble, _context.Musician); } return(View(eAndM)); }