public async Task <GetAllPublicHouseViewModel> GetAll() { var publicHouseVMItemList = new List <PublicHouseGetAllPublicHouseViewModelItem>(); var result = new GetAllPublicHouseViewModel(); IEnumerable <PublicHouseInBook> publicHouseBooksList = await _publicHouseInBookRepository.GetAllPublicHouses(); ILookup <PublicHouse, Book> lookupList = publicHouseBooksList.ToLookup(p => p.PublicHouse, p => p.Book); foreach (IGrouping <PublicHouse, Book> item in lookupList) { var publicHouseVMItem = Mapper.Map <PublicHouse, PublicHouseGetAllPublicHouseViewModelItem>(item.Key); publicHouseVMItem.Books = (item.ToList().FirstOrDefault() == null) ? new List <BookGetAllPublicHouseViewModelItem>() : Mapper.Map <List <Book>, List <BookGetAllPublicHouseViewModelItem> >(item.ToList()); publicHouseVMItemList.Add(publicHouseVMItem); } result.PublicHouses = publicHouseVMItemList; return(result); }
public async Task <IActionResult> GetAll() { GetAllPublicHouseViewModel getAllPublicHouseViewModel = await _service.GetAll(); return(Ok(getAllPublicHouseViewModel)); }