public async Task <object?> HandleAsync(DeleteMovieCommand command, CancellationToken cancellationToken) { _logger.LogDebug($"{GetType().Name} entered."); var orgMovie = await _context .Movies .FirstOrDefaultAsync(movie => movie.Id == command.Id, cancellationToken); if (orgMovie == null) { var message = $"Movie with id '{command.Id}' could not be found."; _logger.LogWarning(message); throw new NotFoundException(message); } _context .Movies .Remove(orgMovie); await _context .SaveChangesAsync(cancellationToken); _logger.LogInformation($"Movie with it '{orgMovie.Id}' and title '{orgMovie.Title}' was removed from store."); _logger.LogDebug($"{GetType().Name} leaving."); return(null); }
public async Task <object?> HandleAsync(CreateMovieCommand command, CancellationToken cancellationToken) { _logger.LogDebug($"{GetType().Name} entered."); var domainMovie = command.ConvertToDomain(); _context.Movies.Add(domainMovie); await _context.SaveChangesAsync(cancellationToken); _logger.LogInformation($"Movie with it '{domainMovie.Id}' and title '{domainMovie.Title}' was created in store."); _logger.LogDebug($"{GetType().Name} leaving."); return(domainMovie); }
public async Task <object?> HandleAsync(UpdateMovieCommand command, CancellationToken cancellationToken) { _logger.LogDebug($"{GetType().Name} entered."); var newMovie = command.ConvertToDomain(); var domainMovie = await _context.FindAsync <DomainMovie>(newMovie.Id); if (domainMovie == null) { var message = $"Movie with id '{newMovie.Id}' could not be found."; _logger.LogWarning(message); throw new NotFoundException(message); } domainMovie.CopyValuesFrom(newMovie); await _context.SaveChangesAsync(cancellationToken); _logger.LogInformation($"Movie with it '{newMovie.Id}' and title '{newMovie.Title}' was updated in store."); _logger.LogDebug($"{GetType().Name} leaving."); return(domainMovie); }