Esempio n. 1
0
 public List <HotelData> SearchByCity(string cityName)
 {
     using (HotelSystemLinqDataContext contex = new HotelSystemLinqDataContext())
     {
         // get hotel ids in city
         AddressOperaions addressOperaions = new AddressOperaions();
         List <string>    hotelIds         = addressOperaions.GetHotelIds(cityName);
         /* get min rate max rate list of hotels */
         RoomOperations            roomOperaions = new RoomOperations();
         Dictionary <string, Rate> rates         = roomOperaions.GetRates(hotelIds);
         // select address and hotel details from table
         var hotels = from hotel
                      in contex.Hotels join address in contex.Addresses on hotel.Id equals address.HotelId
                      where hotelIds.Contains(hotel.Id)
                      select new HotelData
         {
             Id          = hotel.Id,
             Name        = hotel.Name,
             Rating      = hotel.Rating,
             PhoneNumber = hotel.PhoneNumber,
             City        = address.City,
             Locality    = address.Locality,
             MinRate     = rates[hotel.Id].Minimum,
             MaxRate     = rates[hotel.Id].Maximum
         };
         return(hotels.ToList());
     }
 }
 // returns list hotel ids in city
 public List <string> GetHotelIds(string cityName)
 {
     using (HotelSystemLinqDataContext contex = new HotelSystemLinqDataContext())
     {
         var hotelId = from address
                       in contex.Addresses
                       where address.City.ToLower() == cityName.ToLower()
                       select address.HotelId;
         return(hotelId.ToList());
     }
 }
        public Dictionary <string, Rate> GetRates(List <string> hotelIds)
        {
            Dictionary <string, Rate> rates = new Dictionary <string, Rate>();

            foreach (string hotelid in hotelIds)
            {
                using (HotelSystemLinqDataContext contex = new HotelSystemLinqDataContext())
                {
                    Rate rate = new Rate();
                    rate.Maximum = (from room
                                    in contex.Rooms
                                    where room.HotelId == hotelid
                                    select room.Rate).Max();

                    rate.Minimum = (from room
                                    in contex.Rooms
                                    where room.HotelId == hotelid
                                    select room.Rate).Min();
                    rates.Add(hotelid, rate);
                }
            }
            return(rates);
        }