public ActionResult Create([Bind(Include = "Album,Publishers,Tracks")] AlbumEditTemplate template) { if (ModelState.IsValid) { albumRepository.CreateAlbum(template.Album); albumRepository.UpdatePublishersOfAlbum(template.Album.Id, template.Publishers); albumRepository.UpdateTracksOfAlbum(template.Album.Id, template.Tracks); return(RedirectToAction("Index")); } ViewBag.Publishers = new MultiSelectList(publisherRepository.GetAllPublishers(), "Id", "Name", template.Publishers); ViewBag.TracksList = new SelectList(trackRepository.GetAllTracks(), "Id", "Name", template.Tracks.Select(t => t.Track)); return(View(template)); }
// GET: Albums/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Album album = albumRepository.GetAlbumById(id); if (album == null) { return(HttpNotFound()); } AlbumEditTemplate template = new AlbumEditTemplate(); template.Album = album; template.Publishers = albumRepository.GetPublishersOfAlbum(id).Select(p => p.Id).ToList(); template.Tracks = albumRepository.GetTracksOfAlbum(id); ViewBag.Publishers = new MultiSelectList(publisherRepository.GetAllPublishers(), "Id", "Name"); ViewBag.TracksList = new SelectList(trackRepository.GetAllTracks(), "Id", "Name"); return(View(template)); }