public IEnumerable <AuthorGetViewModel> GetAuthors() { List <AuthorInBook> authors = _authorInBookRepository.GetAll(); var getAuthorsViewModel = authors.GroupBy(a => a.Author.Id).Select(x => new AuthorGetViewModel() { Author = x.FirstOrDefault()?.Author, Books = x.Select(z => z.Book).ToList() }); return(getAuthorsViewModel); }
public IEnumerable <BookGetViewModel> GetBooks() { List <AuthorInBook> books = _authorInBookRepository.GetAll(); var getBooksViewModel = books.GroupBy(x => x.Id).Select(x => new BookGetViewModel() { Book = x.FirstOrDefault()?.Book, Authors = x.Select(z => z.Author).ToList() }); return(getBooksViewModel); }