Example #1
0
        /// <summary>
        /// Отели
        /// </summary>
        /// <param name="searchDc"></param>
        /// <param name="sftDc"></param>
        /// <param name="hotelKey">Ключ категории</param>
        /// <param name="mainDc"></param>
        /// <param name="hash"></param>
        /// <returns></returns>
        public static List <DataModel.Hotel> GetHotels(this MtMainDbDataContext mainDc, MtSearchDbDataContext searchDc, SftWebDbDataContext sftDc, int?hotelKey, out string hash)
        {
            List <DataModel.Hotel> result;

            hash = String.Format("{0}_{1}", MethodBase.GetCurrentMethod().Name, hotelKey);
            if ((result = CacheHelper.GetCacheItem <List <DataModel.Hotel> >(hash)) != null)
            {
                return(result);
            }

            result = new List <DataModel.Hotel>();
            var cacheDependencies = new List <string>();

            if (hotelKey == null)
            {
                string hashOut;
                var    hotelCities = (from r in searchDc.GetResorts(sftDc, null, out hashOut)
                                      select r.Id)
                                     .ToList();
                cacheDependencies.Add(hashOut);

                var hotels = (from h in searchDc.GetAllHotels()
                              join c in mainDc.GetAllHotelCats() on h.Stars equals c.COH_Name
                              where hotelCities.Contains(h.CtKey)
                              select
                              new DataModel.Hotel {
                    Id = h.Key, Name = h.Name, ResortId = h.CtKey, HotelCategoryId = c.COH_Id
                })
                             .ToList();

                result.AddRange(hotels);
            }
            else
            {
                string hashOut;
                var    hotel = searchDc.GetHotelByKey(hotelKey.Value, out hashOut);
                cacheDependencies.Add(hashOut);

                if (hotel != null)
                {
                    var cat = mainDc.GetAllHotelCats().SingleOrDefault(c => c.COH_Name == hotel.Stars);
                    if (cat != null)
                    {
                        result.Add(new DataModel.Hotel
                        {
                            HotelCategoryId = cat.COH_Id,
                            Id       = hotel.Key,
                            Name     = hotel.Name,
                            ResortId = hotel.CtKey
                        });
                    }
                }
            }

            cacheDependencies.Add(HotelsExtension.TableName);
            cacheDependencies.Add(HotelCategoriesExtension.TableName);
            CacheHelper.AddCacheData(hash, result, cacheDependencies.ToList(), Globals.Settings.Cache.LongCacheTimeout);
            return(result);
        }
Example #2
0
        /// <summary>
        /// Возвращает список отелей по стране
        /// </summary>
        /// <param name="dc">Контекст БД</param>
        /// <param name="countryKey">Ключ страны</param>
        /// <param name="hash">Хэш кэша</param>
        /// <returns></returns>
        public static IList <HotelSmallClass> GetHotelsByCountry(this MtSearchDbDataContext dc, int countryKey, out string hash)
        {
            List <HotelSmallClass> result;

            hash = String.Format("{0}_{1}", MethodBase.GetCurrentMethod().Name, countryKey);
            if ((result = CacheHelper.GetCacheItem <List <HotelSmallClass> >(hash)) != null)
            {
                return(result);
            }

            result = dc.GetAllHotels().Where(h => h.CnKey == countryKey).ToList();
            CacheHelper.AddCacheData(hash, result, new List <string>()
            {
                TableName
            }, Globals.Settings.Cache.LongCacheTimeout);
            return(result);
        }
Example #3
0
        /// <summary>
        /// Возвращает список соответствий ключей отелей и звездности
        /// </summary>
        /// <param name="dc">Контекст БД</param>
        /// <param name="hotelKeys">Ключи отелей</param>
        /// <param name="hash">Хэш кэша</param>
        /// <returns></returns>
        public static List <Tuple <int, string> > GetHotelKeysStars(this MtSearchDbDataContext dc, IEnumerable <int> hotelKeys, out string hash)
        {
            List <Tuple <int, string> > result;

            hash = String.Format("{0}_{1}", MethodBase.GetCurrentMethod().Name, String.Join(",", hotelKeys));
            if ((result = CacheHelper.GetCacheItem <List <Tuple <int, string> > >(hash)) != null)
            {
                return(result);
            }

            result = dc.GetAllHotels().Where(h => hotelKeys.Contains(h.Key) && !String.IsNullOrEmpty(h.Stars)).Select(h => new Tuple <int, string>(h.Key, h.Stars)).ToList();

            CacheHelper.AddCacheData(hash, result, new List <string>()
            {
                TableName
            }, Globals.Settings.Cache.LongCacheTimeout);
            return(result);
        }
Example #4
0
        /// <summary>
        /// Возвращает отели по ключам
        /// </summary>
        /// <param name="dc">Контекст базы данных</param>
        /// <param name="hotelKeys">Ключи отелей</param>
        /// <param name="hash">Хэш кэша</param>
        /// <returns></returns>
        public static IList <HotelSmallClass> GetHotelsByKeys(this MtSearchDbDataContext dc, IEnumerable <int> hotelKeys, out string hash)
        {
            List <HotelSmallClass> result;

            hash = String.Format("{0}_{1}", MethodBase.GetCurrentMethod().Name, String.Join(",", hotelKeys));
            if ((result = CacheHelper.GetCacheItem <List <HotelSmallClass> >(hash)) != null)
            {
                return(result);
            }

            result = (from h in dc.GetAllHotels()
                      where hotelKeys.Contains(h.Key)
                      select h)
                     .ToList();

            CacheHelper.AddCacheData(hash, result, new List <string>()
            {
                TableName
            }, Globals.Settings.Cache.LongCacheTimeout);
            return(result);
        }
Example #5
0
        /// <summary>
        /// Возвращает отель по ключу
        /// </summary>
        /// <param name="dc">Контекст базы данных</param>
        /// <param name="hotelKey">Ключ отеля</param>
        /// <param name="hash">Хэш кэша</param>
        /// <returns></returns>
        public static HotelSmallClass GetHotelByKey(this MtSearchDbDataContext dc, int hotelKey, out string hash)
        {
            HotelSmallClass result;

            hash = String.Format("{0}_{1}", MethodBase.GetCurrentMethod().Name, hotelKey);
            if ((result = CacheHelper.GetCacheItem <HotelSmallClass>(hash)) != null)
            {
                return(result);
            }

            result = (from h in dc.GetAllHotels()
                      where h.Key == hotelKey
                      select h)
                     .SingleOrDefault();

            CacheHelper.AddCacheData(hash, result, new List <string>()
            {
                TableName
            }, Globals.Settings.Cache.LongCacheTimeout);
            return(result);
        }