public IActionResult Edit(int id) { Serie serie = _mediaService.GetAllSeries().FirstOrDefault(x => x.Id == id); SerieEditViewModel vm = new SerieEditViewModel() { Id = id, Name = serie.Name }; vm.Seasons = _mediaService.GetAllSeasons().Where(z => z.Serie.Id == serie.Id).ToList(); return(View(vm)); }
public async Task <IActionResult> Edit(int id) { Serie serieFromDb = await _mediaDbContext.Series.FindAsync(id); SerieEditViewModel model = new SerieEditViewModel { Id = serieFromDb.Id, Producer = serieFromDb.Producer, ReleaseDate = serieFromDb.ReleaseDate, Title = serieFromDb.Title, Url = serieFromDb.Url, Episode = serieFromDb.Episode }; return(View(model)); }
public async Task <IActionResult> Edit(SerieEditViewModel vm) { if (!TryValidateModel(vm)) { return(View(vm)); } Serie domainSerie = await _mediaDbContext.Series.FindAsync(vm.Id); domainSerie.Title = vm.Title; domainSerie.Episode = vm.Episode; domainSerie.ReleaseDate = vm.ReleaseDate; domainSerie.Url = vm.Url; domainSerie.Producer = vm.Producer; _mediaDbContext.Update(domainSerie); await _mediaDbContext.SaveChangesAsync(); return(RedirectToAction("Detail", new { Id = vm.Id })); }