Ejemplo n.º 1
0
 private AvailabilityResponse Dummy()
 {
     Random rnd = new Random();
     var response = new AvailabilityResponse();
     response.Rooms.Add(new Availability { Room = new Room { Description = "Minimalist room for the economist traveller.", Title = "Sleep Dorm", Id = "1", Rate = 1597 }, AvailableCount = rnd.Next(1, 10) });
     response.Rooms.Add(new Availability { Room = new Room { Description = "Just the basics - bed and bathroom with shower.", Title = "RnR", Id = "2", Rate = 899 }, AvailableCount = rnd.Next(1, 10) });
     response.Rooms.Add(new Availability { Room = new Room { Description = "Bedroom with workspace for the business traveller.", Title = "Working Suite", Id = "3", Rate = 2499 }, AvailableCount = rnd.Next(1, 10) });
     response.Rooms.Add(new Availability { Room = new Room { Description = "Private office space with minimalist sleeping quarters.", Title = "Office Away", Id = "4", Rate = 1200 }, AvailableCount = rnd.Next(1, 10) });
     response.Rooms.Add(new Availability { Room = new Room { Description = "Sleeping, living and dining accomodations.", Title = "Home Away", Id = "5", Rate = 4000 }, AvailableCount = rnd.Next(1, 10) });
     return response;
 }
Ejemplo n.º 2
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;
        }