Example #1
0
        public ActionResult <UpdateMovieResponse> Put([FromBody] UpdateMovieRequest request)
        {
            // validate request model
            _updateMovieRequestValidator.Validate(request);

            // map view model to domain model
            var movie = _mapper.Map <MovieDomainModel>(request.Movie);

            // update existing movie
            var updatedMovie = _movieService.UpdateMovie(movie);

            // prepare response
            var response = new UpdateMovieResponse
            {
                Movie = _mapper.Map <MovieResponseViewModel>(updatedMovie)
            };

            // 200 response
            return(HandleSuccessResponse(response));
        }
        public async Task <ActionResult <MovieViewModel> > Put(int?id, [FromBody] MovieViewModel viewModel)
        {
            var request = new UpdateMovieRequest {
                Movie = viewModel, Id = id
            };

            _updateMovieRequestValidator.Validate(request);

            // id can be in URL, body, or both
            viewModel.Id = id ?? viewModel.Id;

            // map view model to domain model
            var movie = _mapper.Map <MovieDomainModel>(viewModel);

            // update existing movie
            var updatedMovie = await _movieService.UpdateMovieAsync(movie);

            // prepare response
            var response = _mapper.Map <MovieViewModel>(updatedMovie);

            // 200 response
            return(HandleSuccessResponse(response));
        }