public async Task <IActionResult> Edit(int id, MovieWriterEditViewModel model) { if (ModelState.IsValid) { Writer writer = _context.Writers.Find(id); writer.MovieID = model.MovieID; writer.Name = model.Name; writer.DateOfBirth = model.DateOfBirth; _context.Update(writer); await _context.SaveChangesAsync(); } ViewData["MovieID"] = new SelectList(_context.Movies, "ID", "Titel", model.MovieID); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var writer = await _context.Writers .Include(w => w.Movies) .FirstOrDefaultAsync(m => m.ID == id); if (writer == null) { return(NotFound()); } var model = new MovieWriterEditViewModel() { ID = writer.ID, Name = writer.Name, DateOfBirth = writer.DateOfBirth, MovieID = writer.MovieID, Movies = writer.Movies.Titel }; ViewData["MovieID"] = new SelectList(_context.Movies, "ID", "Titel", writer.MovieID); return(View(model)); }