private void MockBookRetrieval() { _booksDbSet.SetDbSetData(new List <Book>().AsQueryable()); _bookInfoService.FindBookByIsbnAsync("123").Returns(Task.FromResult(new ExternalBookInfo { Author = "test", Url = "test", Title = "asd" })); }
private async Task <RetrievedBookInfoDto> GetInfoFromExternalApiAsync(string code) { var bookInfo = await _bookInfoService.FindBookByIsbnAsync(code); _serviceValidator.ThrowIfBookDoesNotExistGoogleApi(bookInfo != null); return(MapGoogleApiBookToDto(bookInfo)); }
public async Task <RetrievedBookInfoDto> FindBookByIsbnAsync(string isbn, int organizationId) { var bookAlreadyExists = _booksDbSet .Any(book => book.OrganizationId == organizationId && book.Code == isbn); _bookServiceValidator.CheckIfBookAlreadyExists(bookAlreadyExists); var result = await _bookInfoService.FindBookByIsbnAsync(isbn); _bookServiceValidator.CheckIfBookWasFoundByIsbnFromExternalProvider(result); var retrievedBookDto = MapBookInfoToDto(result); return(retrievedBookDto); }
public async Task UpdateBookCoversAsync() { var booksWithoutCover = _booksDbSet.Where(book => book.BookCoverUrl == null); foreach (var book in booksWithoutCover) { try { var bookInfo = await _bookService.FindBookByIsbnAsync(book.Code); if (bookInfo?.CoverImageUrl == null) { continue; } book.BookCoverUrl = bookInfo.CoverImageUrl; await _uow.SaveChangesAsync(); } catch (Exception ex) { _logger.Error(ex); } } }