public async Task <IActionResult> UpdateMoviewAsync([FromBody] UpdateMovieRequest movie)
        {
            try
            {
                var filter = Builders <Movie> .Filter.Eq(m => m.Id, movie.Id);

                var updateDifinition = new BsonDocument()
                {
                    {
                        "$set", new BsonDocument()
                        {
                            { "title", movie.Title },
                            { "plot", movie.Plot },
                            { "year", movie.Year },
                            { "imdbId", movie.ImdbId }
                        }
                    }
                };

                var updateOptions = new UpdateOptions();
                updateOptions.IsUpsert = movie.InsertIfNotExist;

                var update = await _dbContext.Movies.UpdateOneAsync(filter, updateDifinition, updateOptions);

                var updated = await this._dbContext.Movies.FindAsync(filter);

                return(Ok(updated));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public MovieListItem UpdateMovie(int id, [FromBody] UpdateMovieRequest movieRequest)
        {
            var movies        = _ctx.Movies;
            var matchingMovie = movies.Find(id);

            if (matchingMovie == null)
            {
                Response.StatusCode = 404;
                var    jsonString = "{\"Error\":\"No Matching Movie with MovieId\"}";
                byte[] data       = Encoding.UTF8.GetBytes(jsonString);
                Response.ContentType = "application/json";
                Response.Body.Write(data, 0, data.Length);
            }

            matchingMovie.MovieName   = movieRequest.MovieName ?? matchingMovie.MovieName;
            matchingMovie.MovieRating = movieRequest.MovieRating ?? matchingMovie.MovieRating;

            _ctx.Movies.Update(matchingMovie);
            _ctx.SaveChanges();

            var matchingMovieListItem = new MovieListItem()
            {
                MovieId     = matchingMovie.MovieId,
                MovieName   = matchingMovie.MovieName,
                MovieRating = matchingMovie.MovieRating
            };

            return(matchingMovieListItem);
        }
示例#3
0
        public void Should_throw_exception_when_movie_is_not_found(
            IWebApiMovieRestContext context,
            UpdateMovieRequestHandler updateMovieRequestHandler,
            UpdateMovieRequest updateMovieRequest,
            Exception exception
            )
        {
            "Given a WebApiMovieRestContext"
            .Given(() => context = new WebApiMovieRestContext().AutoRollback());

            "And a UpdateMovieRequestHandler constructed with the context"
            .And(() => updateMovieRequestHandler = new UpdateMovieRequestHandler(context));

            "And a UpdateMovieRequest containing the id of a Movie that does not exist".
            And(() => updateMovieRequest = new UpdateMovieRequest()
            {
                MovieId = Guid.Empty
            });

            "When handling the UpdateMovieRequest"
            .When(() => exception = Record.Exception(() => updateMovieRequestHandler.Handle(updateMovieRequest)));

            "A ResourceNotFoundException should be thrown"
            .Then(() => exception.Should().BeOfType <ResourceNotFoundException>());

            "With a message indicating the id of the Movie that was not found"
            .Then(() => exception.Message.Should().Be("Movie[Id=00000000-0000-0000-0000-000000000000] could not be found"));
        }
示例#4
0
        public IActionResult Put(int id, [FromBody] UpdateMovieRequest movieRequest)
        {
            if (movieRepository.GetMovieById(id) == null)
            {
                return(NotFound());
            }

            if (movieRequest == null)
            {
                return(StatusCode(400, ModelState));
            }


            if (!ModelState.IsValid)
            {
                return(StatusCode(400, ModelState));
            }

            var movie = movieRepository.UpdateMovie(id, movieRequest);

            if (movie == null)
            {
                var error = new Error()
                {
                    message = "Something went wrong when save movie"
                };
                return(StatusCode(400, error));
            }
            return(Ok(new MovieDTO(movie)));
        }
示例#5
0
        public async Task <IActionResult> UpdateAsync(UpdateMovieRequest request, CancellationToken token)
        {
            _logger.LogInformation("PUT /Movie request accepted");
            var response = await _movieService.UpdateAsync(_mapper.Map <MovieDTO>(request));

            return(Ok(_mapper.Map <MovieResponse>(response)));
        }
示例#6
0
        public async Task <IActionResult> Update(string id, [FromBody] UpdateMovieRequest updateRequest)
        {
            var response = await _movieManager.UpdateAsync(id, updateRequest);

            if (!response.IsSuccess)
            {
                return(BadRequest("Exception Occured While Updating Movie"));
            }

            return(Ok(response));
        }
示例#7
0
        public async Task <IActionResult> UpdateMovie([FromBody] UpdateMovieRequest request)
        {
            try
            {
                var response = await _movieUseCase.Update(request);

                return(await ResponseAsync(response));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public static UpdateMovieRequest AsRequest(this UpdateMovieWebRequest webRequest)
        {
            var result = new UpdateMovieRequest
            {
                Id          = webRequest.Id,
                Title       = webRequest.Title,
                Description = webRequest.Description,
                IsDeleted   = webRequest.IsDeleted,
                RentalDate  = webRequest.Rentaldate,
                IsRented    = webRequest.IsRented
            };

            return(result);
        }
示例#9
0
 public UpdateMovieTest()
 {
     _mediator        = new Mock <IMediator>();
     _faker           = new Faker();
     _id              = Guid.NewGuid();
     _repositoryMovie = MovieRepositoryBuilder.Instance().Find(_id).Build();
     _command         = new UpdateMovieRequest
     {
         Id          = _id,
         Image       = _faker.Image.ToString(),
         Title       = "Title",
         Description = _faker.Lorem.Paragraph(5),
         Duration    = "01:00"
     };
 }
示例#10
0
        public async Task <Result> UpdateAsync(string id, UpdateMovieRequest updateRequest)
        {
            var updatesFilter = Builders <Movie> .Filter.Eq(t => t.Id, id);

            var updates = Builders <Movie>
                          .Update
                          .Set("Description", updateRequest.Description)
                          .Set("ReleaseDate", updateRequest.ReleaseDate)
                          .Set("Rating", updateRequest.Rating)
                          .Set("Duration", updateRequest.Duration);

            var updateResult = await _movieCollection.UpdatePartialAsync(updatesFilter, updates);

            return(ApiUtils.ProcessResult(updateResult));
        }
        public bool UpdateMovie(UpdateMovieRequest request)
        {
            if (request != null)
            {
                var movie = _db.Movies.Where(a => a.Id == request.id).FirstOrDefault();
                if (movie != null)
                {
                    movie.MovieName = string.IsNullOrEmpty(request.name) ? movie.MovieName : request.name;
                    movie.MovieType = string.IsNullOrEmpty(request.type) ? movie.MovieType : request.type;

                    _db.SaveChanges();
                    return(true);
                }
            }
            return(false);
        }
示例#12
0
        public async Task <IActionResult> Update([FromRoute] Guid Id, UpdateMovieRequest request)
        {
            var movie = new Movie // TODO refactor
            {
                MovieGuid = Id,
                Title     = request.Title
            };

            var updateSuccess = await _movieService.UpdateMovieAsync(movie);

            if (updateSuccess)
            {
                return(Ok(movie));
            }

            return(NotFound());
        }
        public async Task <UpdateMovieResponse> UpdateMovieAsync(UpdateMovieRequest request)
        {
            var entity = new MovieEntity
            {
                Id          = request.Id,
                Title       = request.Title,
                Description = request.Description,
                IsDeleted   = request.IsDeleted,
                RentalDate  = request.RentalDate,
                IsRented    = request.IsRented
            };

            var result = new UpdateMovieResponse
            {
                Data = await this.moviesRepository.UpdateMovieAsync(entity)
            };

            return(result);
        }
示例#14
0
        public IHttpActionResult Update(UpdateMovieRequest req)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Movie m = MovieRepoStub.ReadById(req.Id);

            if (m == null)
            {
                return(NotFound());
            }

            m.Title  = req.Title;
            m.Rating = req.Rating;
            MovieRepoStub.Update(m);

            return(Ok(m));
        }
示例#15
0
        public IHttpActionResult Update(UpdateMovieRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Movie movie = MovieRepository.Get(request.MovieId);

            if (movie == null)
            {
                return(NotFound());
            }

            movie.Title  = request.Title;
            movie.Rating = request.Rating;

            MovieRepository.Edit(movie);
            return(Ok(movie));
        }
示例#16
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));
        }
示例#17
0
        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));
        }
示例#18
0
        public Movie UpdateMovie(int id, UpdateMovieRequest movieRequest)
        {
            var movie = dbContext.Movies.Where(m => m.Id == id).FirstOrDefault();

            movie.EndAt = DateTime.Parse(movieRequest.EndAt);
            Coppier <UpdateMovieRequest, Movie> .Copy(movieRequest, movie);

            if (movieRequest.ScreenTypeIds != null)
            {
                var screenTypeToDelete = dbContext.MovieScreenTypes.Where(ms => ms.MovieId == id).ToList();
                if (screenTypeToDelete != null)
                {
                    dbContext.RemoveRange(screenTypeToDelete);
                }

                var screenTypes = dbContext.ScreenTypes.Where(s => movieRequest.ScreenTypeIds.Contains(s.Id)).ToList();

                foreach (var screenType in screenTypes)
                {
                    var movieScreenType = new MovieScreenType()
                    {
                        Movie      = movie,
                        ScreenType = screenType,
                    };
                    dbContext.Add(movieScreenType);
                }
            }

            dbContext.Update(movie);
            var isSuccess = Save();

            if (!isSuccess)
            {
                return(null);
            }
            return(movie);
        }
示例#19
0
        public async Task <Response> Update(UpdateMovieRequest updateMovieRequest)
        {
            var responseMovie = await _mediator.Send(updateMovieRequest, CancellationToken.None);

            return(responseMovie);
        }
 public IActionResult UpdateMovie(UpdateMovieRequest data)
 {
     return(Ok(repository.UpdateMovie(data)));
 }
示例#21
0
        public void Should_update_movie_and_use_existing_genre_if_genre_exists(
            IWebApiMovieRestContext context,
            UpdateMovieRequestHandler updateMovieRequestHandler,
            Genre alreadyExistingGenre,
            Movie newMovie,
            UpdateMovieRequest updateMovieRequest,
            MoviesResponse moviesResponse,
            Movie updatedMovie
            )
        {
            "Given a WebApiMovieRestContext"
            .Given(() => context = new WebApiMovieRestContext().AutoRollback());

            "And a UpdateMovieRequestHandler constructed with the context"
            .And(() => updateMovieRequestHandler = new UpdateMovieRequestHandler(context));

            "And a new Movie that has been inserted into the database".And(() =>
            {
                newMovie = new MovieBuilder().WithGenres(new[] { new Genre("new genre") });

                using (var dbContext = new WebApiMovieRestContext())
                {
                    dbContext.Movies.Add(newMovie);
                    dbContext.SaveChanges();
                }
            });

            "And a Genre that already exists in the database".And(() =>
            {
                var alreadyExistingGenreName = new WebApiMovieRestInitializer()
                                               .SeedMovies().First()
                                               .Genres.First()
                                               .Name;

                using (var dbContext = new WebApiMovieRestContext())
                {
                    alreadyExistingGenre = dbContext.Genres.Single(genre => genre.Name == alreadyExistingGenreName);
                }
            });

            "And a UpdateMovieRequest containing the id of the newly inserted Movie and genre that exists in the database".
            And(() => updateMovieRequest = new UpdateMovieRequestBuilder()
                                           .WithMovieId(newMovie.Id)
                                           .WithDirector("new director")
                                           .WithGenres(new[] { alreadyExistingGenre.Name })
                                           .WithImdbId("newimdbid")
                                           .WithPlot("new plot")
                                           .WithRating(0.1m)
                                           .WithReleaseDate(new DateTime(2000, 01, 01))
                                           .WithTitle("new title"));

            "After handling the UpdateMovieRequest"
            .When(() => moviesResponse = updateMovieRequestHandler.Handle(updateMovieRequest));

            "And commiting the WebApiMovieRestContext"
            .When(() => context.Commit());

            "And retrieving the updated Movie".When(() =>
            {
                using (var dbContext = new WebApiMovieRestContext())
                {
                    updatedMovie = dbContext.Movies
                                   .Include(movie => movie.Genres)
                                   .SingleOrDefault(movie => movie.Id == newMovie.Id);
                }
            });

            "Then the already existing Genre should have be used".Then(() =>
                                                                       updatedMovie.Genres.Single().ShouldBeEquivalentTo(alreadyExistingGenre));

            "And the new movie should have the same values as the request"
            .Then(() => updatedMovie.ShouldBeEquivalentTo(updateMovieRequest, o => o.ExcludingMissingProperties()));

            "And the new movie should have the same genre as the request"
            .Then(() => updatedMovie.Genres.Single().Name.Should().Be(updateMovieRequest.Genres[0]));

            "And the MovieResponse should be the newly updated Movie translated"
            .Then(() => moviesResponse.ShouldBeEquivalentTo(updatedMovie.Yield().ToResponse()));
        }