public async Task <ActionResult <MovieUpdateDTO> > PutGet(int id) { var movieActionResult = await Get(id); if (movieActionResult == null) { return(NotFound()); } var movieDetailDTO = movieActionResult.Value; var selectedGenreIds = movieDetailDTO.Genres.Select(x => x.Id).ToList(); var notSelectedGenres = await _dbContext.Genres .Where(x => !selectedGenreIds.Contains(x.Id)) .ToListAsync(); var model = new MovieUpdateDTO() { Movie = movieDetailDTO.Movie, SelectedGenres = movieDetailDTO.Genres, NotSelectedGenres = notSelectedGenres, Actors = movieDetailDTO.Actors, Theaters = movieDetailDTO.Theaters }; return(model); }
public async Task <IActionResult> Update(int id, [FromBody] MovieUpdateDTO movieDTO) { try { _logger.LogInfo("Update started"); if (id < 1 || movieDTO == null || id != movieDTO.Id) { _logger.LogWarn("Empty request"); return(BadRequest()); } var isExists = await _movieRepository.IsExists(id); if (!isExists) { _logger.LogWarn("Movie does not exists"); return(BadRequest()); } var movie = _mapper.Map <Movie>(movieDTO); var isSuccess = await _movieRepository.Update(movie); if (!isSuccess) { return(InternalError("Movie update failed")); } _logger.LogInfo("Movie updated"); return(NoContent()); } catch (Exception ex) { return(InternalError($"Something went wrong: {ex.Message}")); } }
public async Task <ActionResult <MovieUpdateDTO> > PutGet(int id) { var movieActionResult = await Get(id); if (movieActionResult.Result is NotFoundResult) { return(NotFound()); } var movieDetailDTO = movieActionResult.Value; var selectedGenresIds = movieDetailDTO.Genres.Select(x => x.Id).ToList(); var notSelectedGenres = await dbcontext.GenresRecords .Where(x => !selectedGenresIds.Contains(x.Id)) .ToListAsync(); MovieUpdateDTO model = new MovieUpdateDTO { MovieItem = movieDetailDTO.MovieItem, SelectedGenres = movieDetailDTO.Genres, NotSelectedGenres = notSelectedGenres, Actors = movieDetailDTO.Actors }; return(model); }
public async Task <MovieDTO> PatchAsync(MovieUpdateDTO movie) { this.Logger.LogTrace($"{nameof(this.PutAsync)} called"); var result = await this.MovieUpdateService.UpdateAsync(this.Mapper.Map <MovieUpdateModel>(movie)); return(this.Mapper.Map <MovieDTO>(result)); }
public ActionResult UpdateMovie(int id, MovieUpdateDTO movieUpdateDTO) { var movieFromDb = _repository.GetMovieById(id); if (movieFromDb == null) { return(NotFound()); } _mapper.Map(movieUpdateDTO, movieFromDb); _repository.UpdateMovie(movieFromDb); _repository.SaveChanges(); return(NoContent()); }
public IActionResult Update(int id, [FromBody] MovieUpdateDTO movieUpdateModel) { var movie = mapper.Map <MovieDTO>(movieUpdateModel); movie.ID = id; try { movieService.Update(movie); return(Ok()); } catch (Exception exception) { return(BadRequest(new { message = exception.Message })); } }
public async Task <ActionResult> Put(int id, [FromForm] MovieUpdateDTO movieDto) { try { TryValidateModel(movieDto); var movieDb = await this.context.Movies .Include(x => x.MoviesActors) .Include(x => x.MoviesGenders) .FirstOrDefaultAsync(x => x.Id == id); if (movieDb == null) { return(NotFound()); } movieDb = this.mapper.Map(movieDto, movieDb); if (movieDto.Poster != null) { using (var memoryStream = new MemoryStream()) { await movieDto.Poster.CopyToAsync(memoryStream); var content = memoryStream.ToArray(); var extension = Path.GetExtension(movieDto.Poster.FileName); movieDb.Poster = await this.fileManager.EditFile(content, extension, this.container, movieDb.Poster, movieDto.Poster.ContentType); } } this.orderActors(movieDb); movieDb.Id = id; this.context.Entry(movieDb).State = EntityState.Modified; await this.context.SaveChangesAsync(); return(NoContent()); } catch (Exception ex) { return(BadRequest(ex)); } }
public async Task <MovieUpdateDTO> GetMovieForUpdate(int id) { var movieDetailDTO = await GetDetailsMovieDTO(id); if (movieDetailDTO == null) { return(null); } var selectedGenresIds = movieDetailDTO.Genres.Select(x => x.Id).ToList(); var notSelectedGenres = await context.Genres .Where(x => !selectedGenresIds.Contains(x.Id)) .ToListAsync(); var model = new MovieUpdateDTO(); model.Movie = movieDetailDTO.Movie; model.SelectedGenres = movieDetailDTO.Genres; model.NotSelectedGenres = notSelectedGenres; model.Actors = movieDetailDTO.Actors; return(model); }
public async Task <ActionResult <MovieUpdateDTO> > PutGet(int id) { var movieActionResult = await Get(id); if (movieActionResult.Result is NotFoundResult) { return(NotFound()); } var movieDetailDTO = movieActionResult.Value; var selectedGenresIds = movieDetailDTO.Genres.Select(x => x.ID).ToList(); var notSelectedGenres = await context.Genres .Where(x => !selectedGenresIds.Contains(x.ID)) .ToListAsync(); var model = new MovieUpdateDTO(); model.Movie = movieDetailDTO.Movie; model.SelectedGenres = movieDetailDTO.Genres; model.NotSelectedGenres = notSelectedGenres; model.Actors = movieDetailDTO.Actors; return(model); }