public void TestRoomAvailability()
        {
            var request = new AvailabilityRequest { FromDate = DateTime.Now.Date.AddDays(1), ToDate = DateTime.Now.Date.AddDays(1), RequestedRoomCount = 1, City = "Bangalore" };
            var response = new WebRepository().GetAvailableRoomList(request);

            Assert.IsNotNull(response);
            Assert.IsTrue(response.Rooms.Count > 0);
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            var init = new AvailabilityRequest
            {
                FromDate = DateTime.Now.AddDays(2),
                ToDate = DateTime.Now.AddDays(5),
                RequestedRoomCount = 1,
                City = "Bangalore"
            };

            return View(init);
        }
Exemplo n.º 3
0
        public JsonResult Get(AvailabilityRequest itinerary)
        {
            int roomCount = itinerary.RequestedRoomCount;
            itinerary.RequestedRoomCount = 1;
            var response = availability.Get(itinerary);
            var booking = new BookingRequest
            {
                Guest = new Customer { FirstName = "Hello" },
                TravelDetails = new Itinerary { FromDate = itinerary.FromDate, ToDate = itinerary.ToDate, HotelID = itinerary.City }
            };

            var bundle = new object[] { response, booking };
            return Json(bundle);
        }
Exemplo n.º 4
0
        //from, to, roomtype, city
        public AvailabilityResponse GetAvailableRoomList(AvailabilityRequest request)
        {
            var response = new AvailabilityResponse();
            try
            {
                using (var context = new SpartanHotelsEntities())
                {
                    var aviRooms = from hr in context.HotelRooms
                                   join ht in context.Hotels on hr.HotelID equals ht.HotelID
                                   where ht.City == request.City
                                   select new
                                       {
                                           hr.HotelRoomID,
                                           hr.HotelID,
                                           ht.HotelName,
                                           hr.Rate,
                                           hr.TotalRoomCount,
                                           hr.RoomTypeID,
                                           ht.City,
                                           ht.Locality,
                                           ht.Address,
                                       };

                    var aviReservations = from rs in context.Reservations
                                          where
                                              (rs.FromDate >= request.FromDate && rs.FromDate <= request.ToDate &&
                                               rs.BookStatusID == (int) BookingStatus.Confirmed)
                                          select rs;

                    if (aviReservations.Any())
                    {
                        var totalBooking =
                            aviReservations.GroupBy(tb => new {tb.FromDate, tb.HotelRoomID}).Select(room => new
                                {
                                    room.Key.HotelRoomID,
                                    room.Key.FromDate,
                                    Total = room.Count()
                                }).AsQueryable().GroupBy(a => new {a.HotelRoomID}).Select(b => new
                                    {
                                        b.Key.HotelRoomID,
                                        TotalBookedRooms = b.Max(c => c.Total)

                                    }).AsQueryable();

                        foreach (var avi in aviRooms)
                        {
                            var filteredRoom = totalBooking.FirstOrDefault(a => a.HotelRoomID == avi.HotelRoomID);
                            int roomsBooked = 0;

                            if (filteredRoom != null)
                                roomsBooked = filteredRoom.TotalBookedRooms;

                            if (avi.TotalRoomCount > roomsBooked)
                            {
                                response.Rooms.Add(new Availability()
                                    {
                                        Room = new SpartanHotels.Entities.Room
                                            {
                                                Id = avi.HotelRoomID.ToString(),
                                                Title = avi.RoomTypeID.ToString(),
                                                Rate = (decimal) avi.Rate
                                            },

                                        AvailableCount = (int) avi.TotalRoomCount - roomsBooked
                                    });
                            }
                        }
                    }
                    else
                    {
                        foreach (var avi in aviRooms)
                        {
                            if (avi.TotalRoomCount > 0)
                            {
                                response.Rooms.Add(new Availability()
                                    {

                                        Room = new Entities.Room
                                            {
                                                Id = avi.HotelRoomID.ToString(),
                                                Title = avi.RoomTypeID.ToString(),
                                                Rate = (decimal) avi.Rate
                                            },

                                        AvailableCount = (int) avi.TotalRoomCount
                                    });
                            }
                        }

                    }
                }

            }
            catch (Exception)
            {
                throw;
            }
            return response;
        }
Exemplo n.º 5
0
 public AvailabilityResponse Get(AvailabilityRequest request)
 {
     return reader.GetAvailableRoomList(request);
 }
Exemplo n.º 6
0
        public AvailabilityResponse GetAvailableRoomList(AvailabilityRequest request)
        {
            var dbAccess = new DbAccess();

            return dbAccess.GetAvailableRoomList(request);
        }