//
        // GET: /Room/
        public ActionResult Room(int id)
        {
            var model = new RoomViewModel();

            RoomTypeModel roomType = db.RoomTypes.Find(id);
            string hotelName = db.Hotels.Find(roomType.HotelId).Name;
            int locationId = db.Hotels.Find(roomType.HotelId).LocationId;
            string locationName = db.Locations.Find(locationId).Name;

            model.Room = new RoomTypeViewModel
            {
                RoomType = roomType,HotelName = hotelName,LocationName = locationName
            };

            model.Check = new CheckAvailablityModel()
            {
                RoomTypeId = id, CheckIn = DateTime.Now, Night = 1,Room = 1
            };
            return View(model);
        }
        public ActionResult Room(CheckAvailablityModel model)
        {
            RoomTypeModel roomType = db.RoomTypes.Find(model.RoomTypeId);

            if (ModelState.IsValid)
            {
                //init check in, check out date
                DateTime checkIn = model.CheckIn;
                DateTime checkOut = checkIn.AddDays(model.Night);

                List<int> AvailableUnitIds = CheckAvailableUnit(model.RoomTypeId, checkIn, checkOut);

                if(AvailableUnitIds.Count >= model.Room)
                {
                        List<RoomUnitModel>RoomToBook = new List<RoomUnitModel>();
                        for(int i = 0;i<model.Room;i++)
                        {
                            RoomToBook.Add(db.RoomUnits.Find(AvailableUnitIds.ElementAt(i)));
                        }

                        var detail = new DetailModel();

                        HotelModel hotel = db.Hotels.Find(roomType.HotelId);

                        BookingModel booking = new BookingModel();
                        booking.CheckIn = checkIn;
                        booking.CheckOut = checkOut;
                        booking.NumberNight = model.Night;
                        booking.NumberRoom = model.Room;
                        booking.RoomTypeId = model.RoomTypeId;
                        booking.TotalCharge = roomType.PricePerNight * booking.NumberRoom * booking.NumberNight;
                        booking.BookingStatus = BookingStatus.NEW;

                        detail.Booking = booking;
                        detail.Rooms = RoomToBook;
                        detail.RoomType = roomType;
                        detail.Hotel = hotel;

                        Session["Detail"] = detail;

                        return RedirectToAction("Confirmation","Booking");

                }else
                {
                    string hotelName = db.Hotels.Find(roomType.HotelId).Name;
                    int locationId = db.Hotels.Find(roomType.HotelId).LocationId;
                    string locationName = db.Locations.Find(locationId).Name;

                    RoomViewModel vm = new RoomViewModel();
                    vm.Check = model;
                    vm.Room = new RoomTypeViewModel
                    {
                        RoomType = roomType,HotelName = hotelName,LocationName = locationName
                    };

                    return View(vm);
                }

            }
            else
            {
                string hotelName = db.Hotels.Find(roomType.HotelId).Name;
                int locationId = db.Hotels.Find(roomType.HotelId).LocationId;
                string locationName = db.Locations.Find(locationId).Name;

                RoomViewModel vm = new RoomViewModel();
                vm.Check = model;
                vm.Room = new RoomTypeViewModel
                {
                    RoomType = roomType,
                    HotelName = hotelName,
                    LocationName = locationName
                };

                return View(vm);
            }
        }