Example #1
0
        public static IList <Tuple <int, string> > GetCharterScheduleCitiesFrom(this MtSearchDbDataContext dc, int countryKeyTo, out string hash)
        {
            List <Tuple <int, string> > result;

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

            string hashOut;
            var    cacheDependencies = new List <string>();

            var charterKeys = dc.GetAllCharterKeys(out hashOut);

            cacheDependencies.Add(hashOut);

            result = (from ch in dc.GetAllCharters()
                      join ctto in dc.GetAllCities() on ch.CH_CITYKEYTO equals ctto.CT_KEY
                      join ctfrom in dc.GetAllCities() on ch.CH_CITYKEYFROM equals ctfrom.CT_KEY
                      where charterKeys.Contains(ch.CH_KEY) &&
                      ctto.CT_CNKEY == countryKeyTo
                      select new Tuple <int, string>(ch.CH_CITYKEYFROM, ctfrom.CT_NAME))
                     .Distinct()
                     .ToList();

            cacheDependencies.Add(CharterExtension.TableName);
            cacheDependencies.Add(CitiesExtension.TableName);

            return(result);
        }
Example #2
0
        /// <summary>
        /// Возвращает список пакетов, в которых лежат цены для бронирования авиабилетов
        /// </summary>
        /// <param name="dc">Контекст базы данных</param>
        /// <param name="searchDc">Контекст поисковой БД</param>
        /// <param name="hash">Хэш кэша</param>
        /// <returns>Tuple int, PacketType - ключ пакета, тип пакета (направление туда, обратно или туда/обратно)</returns>
        public static IList <Tuple <int, PacketType> > GetFlightPackets(this MtMainDbDataContext dc, MtSearchDbDataContext searchDc, out string hash)
        {
            List <Tuple <int, PacketType> > result;

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

            var cacheDependencies = new List <string>();

            result = new List <Tuple <int, PacketType> >();

            string hashOut;
            var    packetKeys = dc.GetCharterBookingPackets(out hashOut);

            cacheDependencies.Add(hashOut);

            var packetKeysDates = dc.GetDatesByTours(packetKeys, out hashOut);

            cacheDependencies.Add(hashOut);

            var allPacketServices = dc.GetClassServicesByTurListKeys(ServiceClass.Flight, packetKeysDates.Select(p => p.Item1).Distinct().ToList(), out hashOut);

            cacheDependencies.Add(hashOut);

            var homeCountryKey = (from ct in searchDc.GetAllCities()
                                  where ct.CT_KEY == Globals.Settings.HomeCityKey
                                  select ct.CT_CNKEY)
                                 .Single();

            foreach (var packetKey in packetKeysDates.Select(p => p.Item1).Distinct().ToList())
            {
                var services = (from s in allPacketServices
                                where s.TS_PKKEY == packetKey
                                select s)
                               .ToList();

                if (services.Count > 1)
                {
                    result.Add(new Tuple <int, PacketType>(packetKey, PacketType.TwoWayCharters));
                }
                else if (services.Count == 1)
                {
                    var serviceCountryKey = (from cn in searchDc.GetAllCities()
                                             where cn.CT_KEY == services[0].TS_SUBCODE2
                                             select cn.CT_CNKEY)
                                            .FirstOrDefault();

                    result.Add(serviceCountryKey == homeCountryKey
                        ? new Tuple <int, PacketType>(packetKey, PacketType.DirectCharters)
                        : new Tuple <int, PacketType>(packetKey, PacketType.BackCharters));
                }
            }

            CacheHelper.AddCacheData(hash, result, cacheDependencies.ToList(), Globals.Settings.Cache.LongCacheTimeout);
            return(result);
        }
Example #3
0
        /// <summary>
        /// Возвращает список стран прилета
        /// </summary>
        /// <param name="dc">Контекст поисковой БД</param>
        /// <param name="mainDc">Контекст основной БД</param>
        /// <param name="isOneWay">Является ли перелет в одну сторону или туда/обратно</param>
        /// <param name="cityKeyFrom">Ключ города вылета</param>
        /// <param name="hash">Хэш кэша</param>
        /// <returns></returns>
        public static IList <Tuple <int, string> > GetFlightCountriesTo(this MtSearchDbDataContext dc, MtMainDbDataContext mainDc, bool isOneWay, int cityKeyFrom, out string hash)
        {
            List <Tuple <int, string> > result;

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

            var    cacheDependencies = new List <string>();
            string hashOut;
            var    cities = dc.GetFlightCitiesTo(mainDc, isOneWay, null, cityKeyFrom, out hashOut);

            cacheDependencies.Add(hashOut);

            result = (from cn in dc.GetAllCountries()
                      join ct in dc.GetAllCities() on cn.CN_KEY equals ct.CT_CNKEY
                      where cities.Select(c => c.Item1).ToList().Contains(ct.CT_KEY)
                      select new Tuple <int, string>(cn.CN_KEY, cn.CN_NAME))
                     .Distinct()
                     .OrderBy(c => c.Item2)
                     .ToList();
            cacheDependencies.Add(CitiesExtension.TableName);
            cacheDependencies.Add(CountriesExtension.TableName);

            CacheHelper.AddCacheData(hash, result, cacheDependencies.ToList(), Globals.Settings.Cache.LongCacheTimeout);
            return(result);
        }
Example #4
0
        /// <summary>
        /// Возвращает города по ключу
        /// </summary>
        /// <param name="dc">Контекст базы данных</param>
        /// <param name="cityKeys">Ключи городов</param>
        /// <param name="hash"></param>
        /// <returns></returns>
        public static IList <CityDictionary> GetCitiesByKeys(this MtSearchDbDataContext dc, IEnumerable <int> cityKeys, out string hash)
        {
            List <CityDictionary> result;

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

            result = (from c in dc.GetAllCities()
                      where cityKeys.Contains(c.CT_KEY)
                      select c)
                     .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="cityKey">Ключ города</param>
        /// <returns></returns>
        public static CityDictionary GetCityByKey(this MtSearchDbDataContext dc, int cityKey)
        {
            CityDictionary result;

            var hash = String.Format("{0}_{1}", MethodBase.GetCurrentMethod().Name, cityKey);

            if ((result = CacheHelper.GetCacheItem <CityDictionary>(hash)) != null)
            {
                return(result);
            }

            result = (from c in dc.GetAllCities()
                      where c.CT_KEY == cityKey
                      select c)
                     .FirstOrDefault();

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

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

            var cacheDependencies = new List <string>();

            result = (from c in dc.GetAllCities()
                      where c.CT_KEY == Globals.Settings.HomeCityKey
                      select c.tbl_Country)
                     .Single();

            cacheDependencies.Add(TableName);
            cacheDependencies.Add(CitiesExtension.TableName);

            CacheHelper.AddCacheData(hash, result, cacheDependencies.ToList(), Globals.Settings.Cache.LongCacheTimeout);
            return(result);
        }
Example #7
0
        public static IList <Tuple <int, string> > GetCharterScheduleCountriesTo(this MtSearchDbDataContext dc, out string hash)
        {
            List <Tuple <int, string> > result;

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

            string hashOut;
            var    cacheDependencies = new List <string>();

            var charterKeys = dc.GetAllCharterKeys(out hashOut);

            cacheDependencies.Add(hashOut);

            var homeCountry = dc.GetHomeCountry(out hashOut);

            cacheDependencies.Add(hashOut);

            result = (from ch in dc.GetAllCharters()
                      join ct in dc.GetAllCities() on ch.CH_CITYKEYTO equals ct.CT_KEY
                      join cn in dc.GetAllCountries() on ct.CT_CNKEY equals cn.CN_KEY
                      where charterKeys.Contains(ch.CH_KEY) &&
                      cn.CN_KEY != homeCountry.CN_KEY
                      select new Tuple <int, string>(cn.CN_KEY, cn.CN_NAME))
                     .Distinct()
                     .ToList();

            cacheDependencies.Add(CharterExtension.TableName);
            cacheDependencies.Add(CountriesExtension.TableName);
            cacheDependencies.Add(CitiesExtension.TableName);

            return(result);
        }
Example #8
0
        /// <summary>
        /// Возвращает список городов прилета
        /// </summary>
        /// <param name="dc">Контекст поисковой БД</param>
        /// <param name="mainDc">Контекст основной БД</param>
        /// <param name="isOneWay">Является ли перелет в одну сторону или туда/обратно</param>
        /// <param name="countryKey">Ключ страны прилета</param>
        /// <param name="cityKeyFrom">Ключ города вылета</param>
        /// <param name="hash">Хэш кэша</param>
        /// <returns></returns>
        public static IList <Tuple <int, string> > GetFlightCitiesTo(this MtSearchDbDataContext dc, MtMainDbDataContext mainDc, bool isOneWay, int?countryKey, int cityKeyFrom, out string hash)
        {
            List <Tuple <int, string> > result;

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

            var    cacheDependencies = new List <string>();
            string hashOut;

            var packets =
                mainDc.GetFlightPackets(dc, out hashOut)
                .Where(
                    p =>
                    !isOneWay && p.Item2 == PacketType.TwoWayCharters ||
                    isOneWay && p.Item2 != PacketType.TwoWayCharters)
                .ToList();

            cacheDependencies.Add(hashOut);

            var schedule = dc.GetFlightSchedules(mainDc, packets, out hashOut);

            cacheDependencies.Add(hashOut);

            var cities = new List <int>();

            if (isOneWay)
            {
                cities.AddRange(schedule.Schedule.Where(s => s.FlightParamsFrom == null && s.FlightParamsTo != null)
                                .Where(s => s.FlightParamsTo.CityKeyFrom == cityKeyFrom)
                                .Select(s => s.FlightParamsTo.CityKeyTo)
                                .Distinct()
                                .ToList());

                cities.AddRange(schedule.Schedule.Where(s => s.FlightParamsTo == null && s.FlightParamsFrom != null)
                                .Where(s => s.FlightParamsFrom.CityKeyFrom == cityKeyFrom)
                                .Select(s => s.FlightParamsFrom.CityKeyTo)
                                .Distinct()
                                .ToList());
            }
            else
            {
                cities.AddRange(schedule.Schedule.Where(s => s.FlightParamsFrom != null && s.FlightParamsTo != null)
                                .Where(s => s.FlightParamsFrom.CityKeyTo == cityKeyFrom && s.FlightParamsTo.CityKeyFrom == cityKeyFrom)
                                .Select(s => s.FlightParamsTo.CityKeyTo)
                                .Distinct()
                                .ToList());
            }

            result = (from c in dc.GetAllCities()
                      where cities.Contains(c.CT_KEY) &&
                      (countryKey == null || c.CT_CNKEY == countryKey.Value)
                      select new Tuple <int, string>(c.CT_KEY, c.CT_NAME))
                     .OrderBy(c => c.Item2)
                     .ToList();

            cacheDependencies.Add(CitiesExtension.TableName);

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