public async Task <IActionResult> Copy(CopyMovieViewModel vm) { if (ModelState.IsValid) { Film film = new Film(); vm.ID = 0; int id = await UpdateMovieAsync(vm, film); return(Redirect($"/Movie/ViewMovie/{id}")); //} //return RedirectToAction("Index"); } // If the model is not valid, it is re-seeded and returned to the View. vm.MediaFormats = vm.PopulateList(_context.MediaFormats.ToList()); vm.AudioFormats = vm.PopulateList(_context.AudioFormats.ToList()); vm.AvailableGenres = _context.Genres .Select(x => new SelectListItem { Value = x.ID.ToString(), Text = x.Name, Selected = vm.Genres.Contains(x.ID.ToString()) }) .ToList(); return(View(vm)); }
public IActionResult Copy(int id) { Film editFilm = _context.Films.SingleOrDefault(f => f.ID == id); // If editFilm with the passed in id exists and the User is associated with the Film or Admin, // then the ViewModel is seeded. Otherwise the User is redirected to the Index Action. if (editFilm != null) { List <MediaFormat> mediaFormats = _context.MediaFormats.ToList(); List <AudioFormat> audioFormats = _context.AudioFormats.ToList(); CopyMovieViewModel vm = new CopyMovieViewModel(mediaFormats, audioFormats, editFilm); vm.Genres = _filmServices.GetFilmGenreIds(id); vm.AvailableGenres = _context.Genres .Select(x => new SelectListItem { Value = x.ID.ToString(), Text = x.Name, Selected = vm.Genres.Contains(x.ID.ToString()) }) .ToList(); return(View(vm)); } return(RedirectToAction("Index")); }