Example #1
0
        /// <summary>
        /// Возвращает список room'ов по ключам
        /// </summary>
        /// <param name="dc">Контекст базы данных</param>
        /// <param name="roomKeys">Ключи записей</param>
        /// <param name="hash">Хэш кэша</param>
        /// <returns></returns>
        public static IList <Room> GetRoomsByKeys(this MtSearchDbDataContext dc, IEnumerable <int> roomKeys, out string hash)
        {
            List <Room> result;

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

            result = dc.GetAllRooms().Where(r => roomKeys.Contains(r.RM_KEY)).ToList();

            CacheHelper.AddCacheData(hash, result, new List <string>()
            {
                TableName
            }, Globals.Settings.Cache.LongCacheTimeout);
            return(result);
        }
Example #2
0
        private static SearchResult GetSearchResult(this MtSearchDbDataContext searchDc, MtMainDbDataContext mainDc, SftWebDbDataContext sftDc, long?offerId, int count, int countryId, int departCityId, DateTime dateFrom, DateTime dateTo, ushort adults, ushort kids, IEnumerable <ushort> kidsAges, int nightsMin, int nightsMax, IEnumerable <int> resorts, IEnumerable <int> hotelCategories, IEnumerable <int> hotels, IEnumerable <int> meals, int currencyId, uint?priceMin, uint?priceMax, int?hotelsIsNotInStop, int?ticketsIncluded, int?hasTickets, out string hash)
        {
            SearchResult result;

            hash = String.Format("{0}_{1}", MethodBase.GetCurrentMethod().Name,
                                 CacheHelper.GetCacheKeyHashed(new[]
            {
                offerId.ToString(),
                count.ToString(CultureInfo.InvariantCulture),
                countryId.ToString(CultureInfo.InvariantCulture),
                departCityId.ToString(CultureInfo.InvariantCulture),
                dateFrom.ToString(CultureInfo.InvariantCulture),
                dateTo.ToString(CultureInfo.InvariantCulture),
                adults.ToString(CultureInfo.InvariantCulture),
                kids.ToString(CultureInfo.InvariantCulture),
                kidsAges != null ? String.Join("_", kidsAges) : String.Empty,
                nightsMin.ToString(CultureInfo.InvariantCulture),
                nightsMax.ToString(CultureInfo.InvariantCulture),
                resorts != null ? String.Join("_", resorts) : String.Empty,
                hotelCategories != null ? String.Join("_", hotelCategories) : String.Empty,
                hotels != null ? String.Join("_", hotels) : String.Empty,
                meals != null ? String.Join("_", meals) : String.Empty,
                currencyId.ToString(CultureInfo.InvariantCulture),
                priceMin.ToString(),
                priceMax.ToString(),
                hotelsIsNotInStop.ToString(),
                ticketsIncluded.ToString(),
                hasTickets.ToString()
            }));
            if ((result = CacheHelper.GetCacheItem <SearchResult>(hash)) != null)
            {
                return(result);
            }


            result = new SearchResult();
            var    cacheDependencies = new List <string>();
            string hashOut;
            var    wrongQuery = false;

            if (offerId == null)
            {
                var tourTypes = searchDc.GetTourTypes(sftDc, departCityId, countryId, out hashOut).Keys.ToList();
                cacheDependencies.Add(hashOut);
                if (tourTypes == null || !tourTypes.Any())
                {
                    wrongQuery = true;
                    CacheHelper.AddCacheData(hash, result, cacheDependencies.ToList(), Globals.Settings.Cache.LongCacheTimeout);
                    return(result);
                }

                if (resorts == null || !resorts.Any())
                {
                    resorts = searchDc.GetCitiesTo(sftDc, departCityId, countryId, tourTypes, out hashOut).Keys.ToList();
                    cacheDependencies.Add(hashOut);
                }
                if (resorts == null || !resorts.Any())
                {
                    wrongQuery = true;
                    CacheHelper.AddCacheData(hash, result, cacheDependencies.ToList(), Globals.Settings.Cache.LongCacheTimeout);
                    return(result);
                }

                IList <int> tourKeys =
                    searchDc.GetTours(sftDc, departCityId, countryId, tourTypes, resorts, out hashOut).Keys.ToList();
                cacheDependencies.Add(hashOut);
                if (tourKeys == null || !tourKeys.Any())
                {
                    wrongQuery = true;
                    CacheHelper.AddCacheData(hash, result, cacheDependencies.ToList(), Globals.Settings.Cache.LongCacheTimeout);
                    return(result);
                }

                IList <DateTime> tourDates =
                    searchDc.GetTourDates(sftDc, departCityId, countryId, resorts, tourKeys, out hashOut)
                    .Where(d => d >= dateFrom && d <= dateTo)
                    .ToList();
                cacheDependencies.Add(hashOut);
                if (tourDates == null || !tourDates.Any())
                {
                    wrongQuery = true;
                    CacheHelper.AddCacheData(hash, result, cacheDependencies.ToList(), Globals.Settings.Cache.LongCacheTimeout);
                    return(result);
                }

                IList <int> tourNights =
                    searchDc.GetTourNights(sftDc, departCityId, countryId, resorts, tourKeys, tourDates, out hashOut)
                    .Where(n => n >= nightsMin && n <= nightsMax)
                    .ToList();
                cacheDependencies.Add(hashOut);
                if (tourNights == null || !tourNights.Any())
                {
                    wrongQuery = true;
                    CacheHelper.AddCacheData(hash, result, cacheDependencies.ToList(), Globals.Settings.Cache.LongCacheTimeout);
                    return(result);
                }

                IList <string> hotelStars;
                if (hotelCategories == null || !hotelCategories.Any())
                {
                    hotelStars =
                        searchDc.GetTourHotelClasses(sftDc, departCityId, countryId, resorts, tourKeys, tourDates,
                                                     tourNights, out hashOut).ToList();
                    cacheDependencies.Add(hashOut);
                }
                else
                {
                    hotelStars = mainDc.GetAllHotelCats()
                                 .Where(c => hotelCategories.Contains(c.COH_Id))
                                 .Select(c => c.COH_Name)
                                 .ToList();
                    cacheDependencies.Add(HotelCategoriesExtension.TableName);
                }
                if (hotelStars == null || !hotelStars.Any())
                {
                    wrongQuery = true;
                    CacheHelper.AddCacheData(hash, result, cacheDependencies.ToList(), Globals.Settings.Cache.LongCacheTimeout);
                    return(result);
                }

                if (meals == null || !meals.Any())
                {
                    meals =
                        searchDc.GetTourPansions(sftDc, departCityId, countryId, resorts, tourKeys, tourDates,
                                                 tourNights,
                                                 hotelStars, out hashOut).Keys.ToList();
                    cacheDependencies.Add(hashOut);
                }
                if (meals == null || !meals.Any())
                {
                    wrongQuery = true;
                    CacheHelper.AddCacheData(hash, result, cacheDependencies.ToList(), Globals.Settings.Cache.LongCacheTimeout);
                    return(result);
                }

                if (hotels == null || !hotels.Any())
                {
                    hotels =
                        searchDc.GetTourHotels(sftDc, departCityId, countryId, resorts, tourKeys, tourDates,
                                               tourNights, hotelStars, meals, out hashOut)
                        .Select(h => h.Key)
                        .ToList();
                    cacheDependencies.Add(hashOut);
                }
                if (hotels == null || !hotels.Any())
                {
                    wrongQuery = true;
                    CacheHelper.AddCacheData(hash, result, cacheDependencies.ToList(), Globals.Settings.Cache.LongCacheTimeout);
                    return(result);
                }

                IEnumerable <int> roomKeys = null;
                // если по стране цена за человека, меняем алгоритм
                if (searchDc.IsCountryPriceForMen(countryId))
                {
                    var rooms = searchDc.GetTourRooms(sftDc, departCityId, countryId, resorts, tourKeys,
                                                      tourDates, tourNights, hotels, meals);
                    roomKeys = (from r in searchDc.GetAllRooms()
                                where rooms.Keys.Contains(r.RM_KEY) &&
                                r.RM_NPLACES == adults
                                select r.RM_KEY)
                               .ToList();
                }

                ushort?firstChildYears = null, secondChildYears = null;
                if (kidsAges != null)
                {
                    if (kidsAges.Any())
                    {
                        firstChildYears = kidsAges.ElementAtOrDefault(0);
                    }
                    if (kidsAges.Count() > 1)
                    {
                        secondChildYears = kidsAges.ElementAtOrDefault(1);
                    }
                }
                var hotelQuotaMask = QuotesStates.Request | QuotesStates.No | QuotesStates.Availiable;
                if (hotelsIsNotInStop != null && hotelsIsNotInStop == 1)
                {
                    hotelQuotaMask = hotelQuotaMask - (byte)QuotesStates.No;
                }

                var aviaQuotaMask = QuotesStates.None | QuotesStates.Request | QuotesStates.No | QuotesStates.Availiable;
                if (ticketsIncluded != null && ticketsIncluded == 1)
                {
                    aviaQuotaMask = aviaQuotaMask - (byte)QuotesStates.None;
                }

                if (hasTickets != null && hasTickets == 1)
                {
                    aviaQuotaMask = aviaQuotaMask - (byte)QuotesStates.No - (byte)QuotesStates.Request;
                }

                result = searchDc.PagingOnClient(mainDc, departCityId, countryId, tourKeys, tourDates, tourNights,
                                                 hotels, meals,
                                                 adults, kids, firstChildYears, secondChildYears, roomKeys, hotelQuotaMask, aviaQuotaMask,
                                                 currencyId, priceMin, priceMax, (ushort)count, 0,
                                                 new Tuple <SortingColumn, SortingDirection>(SortingColumn.Price, SortingDirection.Asc), out hashOut);
                cacheDependencies.Add(hashOut);
            }
            else
            {
                var countryCityKeys = mainDc.GetCountryCityKeysByTourKey((int)offerId.Value, out hashOut);
                cacheDependencies.Add(hashOut);

                result = searchDc.PagingOnClient(mainDc, countryCityKeys.Item2, countryCityKeys.Item1, offerId.Value, out hashOut);
                cacheDependencies.Add(hashOut);
            }

            CacheHelper.AddCacheData(hash, result, cacheDependencies.ToList(), Globals.Settings.Cache.LongCacheTimeout);
            return(result);
        }