コード例 #1
0
        public HotelDescriptionPageViewModel GetHotelDescriptionViewModel(Hotels hotels)
        {
            HotelDescriptionPageViewModel hotelsDescriptionPageViewModel = new HotelDescriptionPageViewModel()
            {
                IdHotel              = hotels.IdHotel,
                HotelName            = hotels.HotelName,
                DescriptionTable     = hotels.DescriptionTable,
                Stars                = hotels.Stars,
                IdLocationNavigation = hotels.IdLocationNavigation,

                GaleryImages = context.HotelImages.Where(x => x.IdHotel == hotels.IdHotel).ToArray(),
            };

            hotelsDescriptionPageViewModel.imagesString = new string[hotelsDescriptionPageViewModel.GaleryImages.Length];

            int imageNumber = 0;

            foreach (var item in hotelsDescriptionPageViewModel.GaleryImages)
            {
                hotelsDescriptionPageViewModel.imagesString[imageNumber] = (Convert.ToBase64String(item.ImageHotel));
                imageNumber++;
            }

            return(hotelsDescriptionPageViewModel);
        }
コード例 #2
0
        // GET: Hotels/Details/5
        public async Task <IActionResult> DetailsHotel(int?id, DateTime checkInDate, DateTime checkOutDate)
        {
            if (id == null)
            {
                return(NotFound());
            }


            var hotels = await _context.Hotels
                         .Include(h => h.IdLocationNavigation)
                         .SingleOrDefaultAsync(m => m.IdHotel == id);

            if (hotels == null)
            {
                return(NotFound());
            }
            HotelDescriptionPageViewModel _Hotel = hotelRepositories.GetHotelDescriptionViewModel(hotels);


            for (int i = 1; i < _Hotel.GaleryImages.Length; i++)
            {
                for (int y = 0; y < _Hotel.GaleryImages[i].ImageHotel.Length; y++)
                {
                    _Hotel.GaleryImages[i].ImageHotel.ToString();
                }
            }

            //_Hotel.Rooms =
            var rooms = _context.Rooms.Where(x => x.IdHotel == id).ToList();

            foreach (var room in rooms)
            {
                var reservations = _context.Reservations.Where(x => x.IdRoom == room.IdRoom)
                                   .OrderBy(x => x.CheckOut).ToList();
                bool found = checkOutDate <reservations[0].CheckIn ||
                                           checkInDate> reservations[reservations.Count() - 1].CheckOut;

                for (int i = 0; i < reservations.Count() - 2; ++i)
                {
                    if (reservations[i].CheckOut <checkInDate && reservations[i + 1].CheckIn> checkOutDate)
                    //   checkInDate > reservations[i].CheckOut   && checkOutDate > reservations[i].CheckOut   && checkInDate > reservations[i].CheckOut ||
                    //   reservations[i].CheckIn < checkOutDate && reservations[i].CheckOut < checkOutDate && reservations[i].CheckOut < checkInDate)
                    //   if(!(reservations[i].CheckIn < checkInDate && reservations[i].CheckOut > checkOutDate))
                    {
                        found = true;
                        break;
                    }
                    if (found)
                    {
                        _Hotel.Rooms.Add(room);
                    }
                }
                if (found)
                {
                    _Hotel.Rooms.Add(room);
                }
            }
            var IdCustommer = HttpContext.Session.GetInt32("IdCustomer");

            _Hotel.IdUser = Convert.ToInt32(IdCustommer);

            _Hotel.CheckIn  = checkInDate;
            _Hotel.CheckOut = checkOutDate;
            return(View(_Hotel));
        }