예제 #1
0
        public async Task <Result <Exception, Unit> > Handle(MovieUpdateCommand request, CancellationToken cancellationToken)
        {
            var findMovieCallback = await _movieRepository.GetById(request.Id);

            if (findMovieCallback.IsFailure)
            {
                return(findMovieCallback.Failure);
            }

            var movie = findMovieCallback.Success;

            _mapper.Map(request, movie);

            var findGenreCallback = await _genreRepository.GetById(movie.GenreId);

            if (findGenreCallback.IsFailure)
            {
                return(findGenreCallback.Failure);
            }

            movie.SetGenre(findGenreCallback.Success);
            movie.SetLastModification();

            var updateGenreCallback = await _movieRepository.UpdateAsync(movie);

            if (updateGenreCallback.IsFailure)
            {
                return(updateGenreCallback.Failure);
            }

            return(Unit.Successful);
        }
예제 #2
0
        public async Task ExecuteAsync(MovieUpdateCommand command)
        {
            var item = await MovieRepository.FindAsync(command.Input.Id);

            if (item == null)
            {
                throw new KeyNotFoundException();
            }
            var dto = command.Input;

            item.Title         = dto.Title ?? string.Empty;
            item.ForeignName   = dto.ForeignName ?? string.Empty;
            item.ReleaseDate   = dto.ReleaseDate;
            item.Minutes       = dto.Minutes;
            item.ReleaseRegion = dto.ReleaseRegion ?? string.Empty;
            item.SpaceType     = dto.SpaceType;
            item.Actors        = dto.Actors;
            item.CoverUri      = dto.CoverUri ?? string.Empty;
            item.Images        = dto.Images;
            item.Description   = dto.Description ?? string.Empty;
            item.Categorys     = dto.Categorys;
            item.Tags          = dto.Tags;
            item.Ratings       = dto.Ratings;
            item.Language      = dto.Language ?? string.Empty;
            await MovieRepository.UpdateAsync(item);
        }
        public async Task <Response <Exception, Movie> > Handle(MovieUpdateCommand request, CancellationToken cancellationToken)
        {
            var movieCallback = await _movieRepository.GetByIdAsync(request.Id);

            if (movieCallback.HasError)
            {
                return(movieCallback.Error);
            }

            // Verifica se o genero enviado existe na base
            var genreCallback = await _genreRepository.GetByIdAsync(request.GenreId);

            if (genreCallback.HasError)
            {
                return(genreCallback.Error);
            }

            var movieMap = Mapper.Map(request, movieCallback.Success);

            var newMovieCallback = await _movieRepository.UpdateAsync(movieMap);

            if (newMovieCallback.HasError)
            {
                return(newMovieCallback.Error);
            }

            return(newMovieCallback.Success);
        }
예제 #4
0
        public IHttpActionResult Update(MovieUpdateCommand movie)
        {
            var validator = movie.Validation();

            if (!validator.IsValid)
            {
                return(HandleValidationFailure(validator.Errors));
            }
            return(HandleCallback(() => MovieAppService.Update(movie)));
        }
예제 #5
0
        public IHttpActionResult Update(MovieUpdateCommand command)
        {
            var validator = command.Validate(_service);

            if (!validator.IsValid)
            {
                return(HandleValidationFailure(validator.Errors));
            }

            return(HandleCallback(_service.Update(command)));
        }
        public bool Update(MovieUpdateCommand movie)
        {
            var movieDb = MovieRepository.GetById(movie.Id);

            if (movieDb == null)
            {
                throw new NotFoundException("Registro não encontrado!");
            }

            var movieEdit = Mapper.Map(movie, movieDb);

            return(MovieRepository.Update(movieEdit));
        }
        private MovieUpdateCommand MovieUpdateCommandData()
        {
            var movieUpdateCommand = new MovieUpdateCommand()
            {
                MovieIdentity = Guid.Parse("CAD67740-C13D-4E74-9DF2-9233B4C59390"),
                Title         = "Who am I",
                ReleaseDate   = new System.DateTime(1995, 1, 1),
                AggregateId   = Guid.Parse("94A1AAB9-1FC2-4EFC-9CFC-12AD6BB1480B"),
                StateId       = Guid.NewGuid()
            };

            return(movieUpdateCommand);
        }
예제 #8
0
        public async Task <bool> UpdateAsync(MovieUpdateCommand command)
        {
            var movie = await _repository.SingleOrDefaultAsync(x => x.ID == command.ID, tracking : false);

            Guard.Against(movie, ErrorType.NotFound);

            var moviesCountByName = await _repository.CountAsync(x => x.Title.Equals(command.Title) && x.ID != command.ID);

            Guard.Against(moviesCountByName > 0, ErrorType.Duplicating);

            movie = _mapper.Map <Movie>(command);

            _repository.Update(movie);

            return(await CommitAsync() > 0);
        }
예제 #9
0
        public async Task <IActionResult> Edit(string id, [Bind("Id,Title,Director,Actors,Image, Year")] MovieViewModel movie, CancellationToken cancellationToken = default)
        {
            if (id != movie.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                // TODO handle concurrency errors
                var request = new MovieUpdateCommand {
                    MovieViewModel = movie, Id = id
                };

                var updateResult = await _mediator.Send(request, cancellationToken);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
        public MovieUpdateCommandHandlerTests()
        {
            _fixture = new Fixture();
            _fixture.Behaviors.Add(new OmitOnRecursionBehavior());

            _context = InitializeDatabase();

            _testCommand = CreateTestCommand(
                Guid.NewGuid(),
                CompletionStatusReference.Completed,
                false,
                false,
                1,
                Guid.NewGuid());

            var checkout = _fixture
                           .Build <CheckoutRecord>()
                           .With(c => c.ModifiedOn, DateTimeOffset.UtcNow)
                           .Create();

            var itemStorage = _fixture
                              .Build <ItemStorageRecord>()
                              .With(a => a.ModifiedOn, DateTimeOffset.UtcNow)
                              .Create();

            _testMovie = _fixture
                         .Build <MovieRecord>()
                         .With(a => a.Id, _testCommand.MovieId)
                         .With(a => a.Checkout, checkout)
                         .With(a => a.UpdatedOn, DateTimeOffset.UtcNow)
                         .With(a => a.ItemStorage, itemStorage)
                         .With(a => a.TimesCompleted, 1)
                         .With(a => a.Title, _testCommand.Title)
                         .With(a => a.Type, _testCommand.Type)
                         .With(a => a.User, _testCommand.User)
                         .With(a => a.UserId, _testCommand.User.Id)
                         .Create();

            _handler = new MovieUpdateCommandHandler(_context);
        }
예제 #11
0
 public async Task <IActionResult> UpdateAsync(MovieUpdateCommand command)
 {
     return(Ok(await _movieService.UpdateAsync(command)));
 }
 public Task ExecuteAsync(MovieUpdateCommand command)
 {
     MovieRepository.Update(command.AggregateRoot);
     return(Task.FromResult(1));
 }
 public void Execute(MovieUpdateCommand command)
 {
     MovieRepository.Update(command.AggregateRoot);
 }
 public Task <IActionResult> UpdateMovieAsync(
     [FromBody] MovieUpdateCommand command,
     [FromServices] IMovieUpdateApiCommandHandler movieUpdateApiCommandHandler
     ) => movieUpdateApiCommandHandler.HandleAsync(this, command);
예제 #15
0
 public async Task <IActionResult> PutAsync([FromBody] MovieUpdateCommand command)
 {
     return(HandleCommand(await _mediator.Send(command)));
 }
        async Task <object> ICommandHandler <MovieUpdateCommand, object> .HandleAsync(MovieUpdateCommand command)
        {
            try
            {
                // Subscribe Data Event Store.
                movieUpdateRepository.DataEventStoreHandler += MovieUpdateRepository_DataEventStoreHandler;

                // Call update Repository
                var repositoryResponse = await movieUpdateRepository?.UpdateAsync(this.mapper.Map <MovieModel>(command));

                if (repositoryResponse == false)
                {
                    return(await base.MovieExistMessageAsync());
                }

                return(repositoryResponse);
            }
            catch
            {
                throw;
            }
            finally
            {
                movieUpdateRepository.DataEventStoreHandler -= MovieUpdateRepository_DataEventStoreHandler;
            }
        }
 async Task <IActionResult> IApiCommandHandler <MovieUpdateCommand> .HandleAsync(ControllerBase controllerBase, MovieUpdateCommand command)
 {
     try
     {
         if (command == null)
         {
             return(controllerBase?.BadRequest());
         }
         return(controllerBase?.Ok(await movieUpdateCommandHandler?.HandleAsync(command)));
     }
     catch
     {
         throw;
     }
 }