public GetPublicationHouseListViewModel GetAll() { var publicationHouses = _publicationHouseRepo.GetAll(); var result = new GetPublicationHouseListViewModel(); foreach (var publicationHouse in publicationHouses) { result.PublicationHouses.Add(new PublicationHouseGetPublicationHouseListViewModelItem() { Id = publicationHouse.Id, Name = publicationHouse.Name, Adress = publicationHouse.Adress }); } return(result); }
public GetBookListViewModel GetAll() { var books = _bookRepository.GetAll(); var result = new GetBookListViewModel(); foreach (var book in books) { result.Books.Add(new BookGetBookListViewModelItem() { Id = book.Id, Name = book.Name, AuthorId = book.AuthorId, YearOfPublication = book.YearOfPublication, Author = new GetAuthorViewModel() { Id = book.Author.Id, Name = book.Author.Name } }); } var pHouses = _publicationHouseRepository.GetAll(); var publicHouseBook = _publicationHouseInBookRepository.GetAll(); foreach (var book in result.Books) { var currentPublicHouseBook = publicHouseBook.Where(x => x.BookId == book.Id).Select(x => x.PublicationHouseId).ToList(); var publicationHouses = pHouses.Where(x => currentPublicHouseBook.Contains(x.Id)).ToList(); book.PublicationHouses = new List <GetPublicationHouseViewModel>(); foreach (var publicationHouse in publicationHouses) { book.PublicationHouses.Add(new GetPublicationHouseViewModel() { Id = publicationHouse.Id, Name = publicationHouse.Name, Adress = publicationHouse.Adress }); } } return(result); }