public override async Task <AddBookRequest> HandleAsync(AddBookRequest command, CancellationToken cancellationToken = new CancellationToken()) { IEnumerable <AuthorModel> authors = null; if (command.Book.Authors != null && command.Book.Authors.Any()) { authors = await _authorRepository.GetAuthorByIds(command.LibraryId, command.Book.Authors.Select(a => a.Id), cancellationToken); if (authors.Count() != command.Book.Authors.Count()) { throw new BadRequestException(); } } if (authors == null || authors.FirstOrDefault() == null) { throw new BadRequestException(); } SeriesModel series = null; if (command.Book.SeriesId.HasValue) { series = await _seriesRepository.GetSeriesById(command.LibraryId, command.Book.SeriesId.Value, cancellationToken); if (series == null) { throw new BadRequestException(); } } IEnumerable <CategoryModel> categories = null; if (command.Book.Categories != null && command.Book.Categories.Any()) { categories = await _categoryRepository.GetCategoriesByIds(command.LibraryId, command.Book.Categories.Select(c => c.Id), cancellationToken); if (categories.Count() != command.Book.Categories.Count()) { throw new BadRequestException(); } } command.Result = await _bookRepository.AddBook(command.LibraryId, command.Book, command.AccountId, cancellationToken); command.Result.SeriesName = series?.Name; command.Result.Authors = authors?.ToList(); command.Result.Categories = categories?.ToList(); return(await base.HandleAsync(command, cancellationToken)); }
public AddSeriesRequest(int libraryId, SeriesModel series) : base(libraryId) { Series = series; }