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 <Boolean> UpdateMovie(CreateUpdateMovieDto movieDto, IFormFile posterImage) { if (posterImage != null) { movieDto.Poster = _fileUploadService.UploadFile(posterImage, "upload"); } var updateMovie = _mapper.Map <Movie>(movieDto); return(await _movieRepository.Update(updateMovie)); }
public async Task <int> CreateMovie(CreateUpdateMovieDto movieDto, IFormFile posterImage) { if (posterImage != null) { movieDto.Poster = _fileUploadService.UploadFile(posterImage, "movies"); } var newMovie = _mapper.Map <Movie>(movieDto); return(await _movieRepository.Add(newMovie)); }