public async Task <ResponseBookPreviewViewModel> GetBooks(RequestGetBookViewModel requestViewModel) { RequestGetBooksModel requestModel = _mapper.Map <RequestGetBooksModel>(requestViewModel); List <Book> books = await _bookRepository.GetByFilters(requestModel); ResponseBookPreviewViewModel result = await GetMappedBooks(books, requestModel); return(result); }
private async Task <ResponseBookPreviewViewModel> GetMappedBooks(List <Book> books, RequestGetBooksModel requestModel) { List <int> booksIds = books.Select(book => book.Id).ToList(); List <AuthorBooks> authorBooks = await _authorBooksRepository.GetByBooksIds(booksIds); List <int> authorsIds = authorBooks.Select(item => item.AuthorId).Distinct().ToList(); List <Author> authors = await _authorRepository.GetAuthorsByIds(authorsIds); ResponseBookPreviewViewModel result = await MapBookToPreviewViewModel(books, authorBooks, authors); result.TotalCount = await _bookRepository.GetTotalCount(requestModel); return(result); }
private async Task <ResponseBookPreviewViewModel> MapBookToPreviewViewModel(List <Book> books, List <AuthorBooks> authorBooks, List <Author> authors) { var result = new ResponseBookPreviewViewModel(); result.Data = new List <BaseBookViewModelItem>(); foreach (Book book in books) { List <string> booksToResult = GetAuthorsByBook(book, authorBooks, authors); var toResult = new BaseBookViewModelItem(); toResult = _mapper.Map <BaseBookViewModelItem>(book); toResult.Authors.AddRange(booksToResult); toResult.Image = await _dropBoxManager.GetFileLink(1); result.Data.Add(toResult); } return(result); }
public async Task <ResponseBookPreviewViewModel> GetBooks([FromBody] RequestGetBookViewModel requestModel) { ResponseBookPreviewViewModel books = await _bookService.GetBooks(requestModel); return(books); }