public ActionResult UpdateMovie(int id, MovieUpdateDto movieUpdateDto) { if (movieUpdateDto.GenreId <= 0) { return(BadRequest(new { Message = "GenreId was not supplied in request body" })); } var foundMovieModel = this.movieRepo.GetById(id); if (foundMovieModel == null) { return(NotFound(new { Message = "No movie found with given id", Action = "UpdateMovie in MoviesController", HTTPMethod = "PUT" })); } else { this.mapper.Map(movieUpdateDto, foundMovieModel); if (!this.movieRepo.SaveChanges()) { return(StatusCode(500)); } return(NoContent()); } }
public async Task <IActionResult> UpdateMovie([FromBody] MovieUpdateDto updateMovie) { var movie = await _movieRepository.GetMovieAsyncr(updateMovie.Id); if (movie == null) { return(BadRequest()); } movie.Title = updateMovie.Title; movie.Category = updateMovie.Category; movie.Description = updateMovie.Description; var movieToUpdate = _movieRepository.UpdateMovie(movie); if (movieToUpdate == null) { return(BadRequest("Impossible to update a movie!")); } await _movieRepository.SaveChangesAsync(); return(Ok(_mapper.Map <MovieDto>(movieToUpdate))); }
public async Task <IActionResult> UpdateMovie(int id, MovieUpdateDto movieUpdateDto) { try { await _moviesService.UpdateAndSaveAsync(id, movieUpdateDto); } catch (Exception) { return(NotFound()); } return(NoContent()); }
private async Task Update(int id, MovieUpdateDto dto) { var movie = await _moviesRepository.GetByIdAsync(id); //Хорошим решением будет сделать свои ексепшины и их возвращать //Но это уже как-то сам if (movie == null) { throw new ArgumentException($"Movie with id : {id} not found"); } _mapper.Map(dto, movie); _moviesRepository.Update(movie); }
public async Task <ActionResult> UpdateMovie(string id, MovieUpdateDto movieUpdateDto) { var movieFromRepo = await _dbContext.GetAsync <Movie>(_collectionName, id); if (movieFromRepo is null) { return(NotFound()); } var movie = _mapper.Map(movieUpdateDto, movieFromRepo); await _dbContext.UpdateAsync(_collectionName, id, movie); return(NoContent()); }
public IActionResult UpdateMovie(int id, [FromBody] MovieUpdateDto movieUpdateDto) { if (movieUpdateDto == null || id != movieUpdateDto.Id) { return(BadRequest(ModelState)); } var movie = _mapper.Map <Movie>(movieUpdateDto); if (!_movieRepo.UpdateMovie(movie)) { ModelState.AddModelError("", $"Algo salió mal al actualizar la pelicula {movie.Name}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public async Task <ActionResult <AppMovie> > CreateMovie(MovieUpdateDto movieUpdate) { if (await MovieExists(movieUpdate.MovieId)) { return(await UpdateMovie(movieUpdate)); } else { var movie = new AppMovie { MovieName = movieUpdate.MovieName.ToLower(), Like = movieUpdate.Like, Dislike = movieUpdate.Dislike, MovieId = movieUpdate.MovieId }; _context.AppMovies.Add(movie); await _context.SaveChangesAsync(); return(Ok(movie)); } }
public async Task <ActionResult <AppMovie> > UpdateMovie(MovieUpdateDto movieUpdateDto) { if (movieUpdateDto.Like == 1) { var movieId = movieUpdateDto.MovieId; var movie = await _context.AppMovies.FirstOrDefaultAsync(x => x.MovieId == movieId); movie.Like = movie.Like + 1; await _context.SaveChangesAsync(); var movieUp = await _context.AppMovies.SingleOrDefaultAsync(x => x.MovieId == movieId); return(movieUp); } else if (movieUpdateDto.Dislike == 1) { var movieId = movieUpdateDto.MovieId; var movie = await _context.AppMovies.FirstOrDefaultAsync(x => x.MovieId == movieId); movie.Dislike = movie.Dislike + 1; await _context.SaveChangesAsync(); var movieUp = await _context.AppMovies.SingleOrDefaultAsync(x => x.MovieId == movieId); return(movieUp); } else { var movieId = movieUpdateDto.MovieId; var movieUp = await _context.AppMovies.SingleOrDefaultAsync(x => x.MovieId == movieId); return(movieUp); } }
public IActionResult UpdateMovie(int id, [FromBody] MovieUpdateDto movie) { if (movie == null) { return(BadRequest()); } if (string.Equals(movie.Description, movie.Title)) { ModelState.AddModelError("Description", "Description and title cannot be the same."); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_moviesRepository.MovieExists(id)) { return(NotFound()); } var movieToUpdate = _moviesRepository.GetMovie(id); if (movieToUpdate == null) { return(NotFound()); } Mapper.Map(movie, movieToUpdate); if (!_moviesRepository.Save()) { return(StatusCode(500, "Issue updating movie. Please try again.")); } return(NoContent()); }
public Movie Update(MovieUpdateDto dto) { var entity = this.GetDetail(dto.Id); entity.Title = dto.Title; entity.Length = dto.Length; entity.Content = dto.Content; entity.Tags = dto.Tags != null?string.Join(',', dto.Tags) : null; entity.CategoryId = dto.CategoryId; entity.Released = dateTimeUtils.Parse(dto.Released); if (dto.Upload != null) { if (entity.Img != null) { fileService.Remove(entity.Img); } entity.Img = fileService.Save(dto.Upload); } return(repository.Update(entity)); }
public async Task UpdateAndSaveAsync(int id, MovieUpdateDto dto) { await Update(id, dto); DatabaseSaveChanges(); }
public virtual Task <MovieDto> UpdateAsync(long id, MovieUpdateDto input) { return(_movieAppService.UpdateAsync(id, input)); }