コード例 #1
0
        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);
        }
コード例 #2
0
        public async Task <IActionResult> GetAll()
        {
            GetAllPublicHouseViewModel getAllPublicHouseViewModel = await _service.GetAll();

            return(Ok(getAllPublicHouseViewModel));
        }