public async Task <Unit> Handle(AddMovieCommand request, CancellationToken cancellationToken) { var director = await _directorRepository.GetByNameAsync(request.Director, cancellationToken); if (director is null) { director = new Director { FullName = request.Director }; await _directorRepository.AddAsync(director, cancellationToken); } var movie = new Movie { PublishYear = request.PublishYear, BoxOffice = request.BoxOffice, ImdbRate = request.ImdbRate, Name = request.Name, Director = director }; await _movieRepository.AddAsync(movie, cancellationToken); await _db.SaveChangesAsync(cancellationToken); await _channel.AddAsync(new MovieAddedEvent { MovieId = movie.Id }, cancellationToken); return(Unit.Value); }
public async Task <Unit> Handle(DeleteMovieCommand request, CancellationToken cancellationToken) { var movie = await _movieRepository.GetByIdAsync(request.MovieId, cancellationToken); if (!(movie is null)) { _movieRepository.Delete(movie); await _db.SaveChangesAsync(cancellationToken); await _channel.AddAsync(new MovieDeletedEvent { MovieId = movie.Id }, cancellationToken); } return(Unit.Value); }