Exemplo n.º 1
0
        public IActionResult GetHotelsFromSelection(int countryId, int cityId, string selectedHotelCategories, int page)
        {
            char[]     sep = new char[] { ';' };
            List <int> selectedHotelCategoriesList = new List <int>();

            if (selectedHotelCategories != null)
            {
                foreach (string item in selectedHotelCategories.Trim().Split(sep))
                {
                    selectedHotelCategoriesList.Add(int.Parse(item));
                }
            }

            List <Hotel> hotels = _context.Hotels.ToList();

            if (countryId > 0)
            {
                hotels = hotels.Where(h => h.City.CountryId == countryId).ToList();
            }
            if (cityId > 0)
            {
                hotels = hotels.Where(h => h.CityId == cityId).ToList();
            }
            if (selectedHotelCategoriesList.Count > 0)
            {
                hotels = hotels.Where(h => selectedHotelCategoriesList.Contains(h.HotelCategoryId)).ToList();
            }

            List <ShortHotelViewModel> hotelsModel = new List <ShortHotelViewModel>();

            foreach (Hotel hotel in hotels)
            {
                List <decimal> prices = new List <decimal>();
                foreach (Tour tour in _context.Tours.Where(t => t.HotelRoom.HotelId == hotel.Id).ToList())
                {
                    prices.Add(tour.Price);
                }
                ShortHotelViewModel item = new ShortHotelViewModel
                {
                    Hotel        = hotel,
                    MinTourPrice = prices.Count > 0 ? prices.Min() : 0,
                    MaxTourPrice = prices.Count > 0 ? prices.Max() : 0
                };
                hotelsModel.Add(item);
            }

            HotelOffersViewModel model = new HotelOffersViewModel
            {
                Hotels = hotelsModel,
                HotelOffersPagination = new HotelOffersPaginationViewModel(hotelsModel.Count, page)
            };

            return(ViewComponent("HotelOffers", new { hotelOffersViewModel = model }));
        }
Exemplo n.º 2
0
        public IViewComponentResult Invoke(HotelOffersViewModel hotelOffersViewModel)
        {
            hotelOffersViewModel.Hotels = hotelOffersViewModel.Hotels.Skip((hotelOffersViewModel.HotelOffersPagination.CurrentPage - 1) * hotelOffersViewModel.HotelOffersPagination.PageSize).Take(hotelOffersViewModel.HotelOffersPagination.PageSize).ToList();

            return(View("_HotelOffers", hotelOffersViewModel));
        }