public async Task <IActionResult> Save(CreateUpdateMovieDto movie, IFormFile posterImage, string newDirectorName) { if (movie.DirectorId <= 0 && !string.IsNullOrWhiteSpace(newDirectorName)) { var newDirector = new Director { Name = newDirectorName }; movie.DirectorId = await _movieLibraryService.AddDirectorReturnId(newDirector); } if (movie.Id == 0) { // New movie var movieId = await _movieLibraryService.CreateMovie(movie, posterImage); if (movieId > 0) { return(RedirectToAction("Index", "Movies")); } } else { //Update existing movie if (await _movieLibraryService.UpdateMovie(movie, posterImage)) { RedirectToAction("Index", "Movies"); } else { RedirectToAction("Details", "Movies", new { Id = movie.Id }); } } return(RedirectToAction("Index", "Movies")); }
public async Task <IActionResult> Save(Director director) { if (director.Id == 0) { // New director var directorId = await _movieLibraryService.AddDirectorReturnId(director); if (directorId > 0) { return(RedirectToAction("Index", "Directors")); } } else { //Update existing director if (await _movieLibraryService.UpdateDirector(director)) { RedirectToAction("Index", "Directors"); } else { RedirectToAction("Details", "Directors", new { Id = director.Id }); } } return(RedirectToAction("Index", "Directors")); }