public ActionResult ManageMusicians(int id) { Instrument instrument = _instrumentRepository.GetById(id); List <int> selecteMusicianIds = instrument.Musicians.Select(m => m.Id).ToList(); List <Musician> allMusicians = _musicianRepository.GetAll(); ManageMusiciansViewModel vm = new ManageMusiciansViewModel() { Instrument = instrument, SelectedMusicianIds = selecteMusicianIds, AllMusicians = allMusicians, }; return(View(vm)); }
public ActionResult ManageMusicians(int id, List <int> selectedMusicianIds) { try { _instrumentRepository.UpdateMusicians(id, selectedMusicianIds); return(RedirectToAction(nameof(Index))); } catch { Instrument instrument = _instrumentRepository.GetById(id); List <int> selecteMusicianIds = instrument.Musicians.Select(m => m.Id).ToList(); List <Musician> allMusicians = _musicianRepository.GetAll(); ManageMusiciansViewModel vm = new ManageMusiciansViewModel() { Instrument = instrument, SelectedMusicianIds = selecteMusicianIds, AllMusicians = allMusicians, }; return(View(vm)); } }