public async Task Handle(UpdateFilmCommand command) { var validationResult = await _validator.ValidateAsync(command); if (!validationResult.IsValid) { await _eventService.RaiseEvent(new ValidationFailedEvent(validationResult)); return; } var record = await _filmReader.GetFilmById(command.FilmId); _unitOfWork.Execute(() => { record.Title = command.Title; record.RuntimeInMinutes = command.RuntimeInMinutes; // TODO: Audit the changes }); await _eventService.RaiseEvent(new FilmUpdatedEvent { Film = Film.FromRecord(record) }); }
public async Task Handle(SelectWatchNextCommand command) { var validationResult = await _validator.ValidateAsync(command); if (!validationResult.IsValid) { await _eventService.RaiseEvent(new ValidationFailedEvent(validationResult)); return; } FilmRecord filmRecord; if (command.FilmId.HasValue) { filmRecord = await _filmReader.GetFilmById(command.FilmId.Value); } else { var mostRecentWatchNext = await _watchNextReader.GetMostRecentWatchNext(command.UserId); filmRecord = await _filmReader.GetRandomUnwatchedFilm(command.UserId, mostRecentWatchNext?.Id); } await _watchNextWriter.MakeSelection(filmRecord.Id, filmRecord.OwnedByUserId); await _eventService.RaiseEvent(new WatchNextSelectedEvent { Film = Film.FromRecord(filmRecord) }); }
public async Task <IActionResult> GetFilm([FromRoute] long id) { var record = await _filmReader.GetFilmById(id); if (record == null) { return(NotFound()); } return(Ok(FilmResponse.FromRecord(record))); }
private async Task <bool> FilmExists(long filmId, CancellationToken cancellationToken) { return((await _filmReader.GetFilmById(filmId)) != null); }