Example #1
0
        public static Tuple <SearchResult, List <Tour> > GetTours(this MtSearchDbDataContext searchDc, MtMainDbDataContext mainDc, SftWebDbDataContext sftDc,
                                                                  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)
        {
            Tuple <SearchResult, List <Tour> > result;

            hash = String.Format("{0}_{1}", MethodBase.GetCurrentMethod().Name,
                                 CacheHelper.GetCacheKeyHashed(new[]
            {
                count.ToString(),
                countryId.ToString(),
                departCityId.ToString(),
                dateFrom.ToString(),
                dateTo.ToString(),
                adults.ToString(),
                kids.ToString(),
                kidsAges != null ? String.Join("_", kidsAges) : String.Empty,
                nightsMin.ToString(),
                nightsMax.ToString(),
                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(),
                priceMin.ToString(),
                priceMax.ToString(),
                hotelsIsNotInStop.ToString(),
                ticketsIncluded.ToString(),
                hasTickets.ToString()
            }));
            if ((result = CacheHelper.GetCacheItem <Tuple <SearchResult, List <Tour> > >(hash)) != null)
            {
                return(result);
            }

            string hashOut;
            var    cacheDependencies = new List <string>();
            var    searchResult      = searchDc.GetSearchResult(mainDc, sftDc, null, count, countryId, departCityId, dateFrom,
                                                                dateTo, adults, kids, kidsAges, nightsMin, nightsMax, resorts, hotelCategories, hotels, meals,
                                                                currencyId, priceMin, priceMax, hotelsIsNotInStop, ticketsIncluded, hasTickets, out hashOut);

            cacheDependencies.Add(hashOut);
            var tours = searchDc.ConvertSearchItemsToTours(mainDc, searchResult.SearchItems, currencyId);

            result = new Tuple <SearchResult, List <Tour> >(searchResult, tours);

            CacheHelper.AddCacheData(hash, result, cacheDependencies.ToList(), Globals.Settings.Cache.LongCacheTimeout);
            return(result);
        }
Example #2
0
        public static Tuple <SearchResult, List <Tour> > GetTours(this MtSearchDbDataContext searchDc, MtMainDbDataContext mainDc, SftWebDbDataContext sftDc, long offerId, int currencyId, out string hash)
        {
            Tuple <SearchResult, List <Tour> > result;

            hash = String.Format("{0}_{1}_{2}", MethodBase.GetCurrentMethod().Name, offerId, currencyId);

            if ((result = CacheHelper.GetCacheItem <Tuple <SearchResult, List <Tour> > >(hash)) != null)
            {
                return(result);
            }

            string hashOut;
            var    cacheDependencies = new List <string>();
            var    searchResult      = searchDc.GetSearchResult(mainDc, sftDc, offerId, currencyId, out hashOut);

            cacheDependencies.Add(hashOut);
            var tours = searchDc.ConvertSearchItemsToTours(mainDc, searchResult.SearchItems, currencyId);

            result = new Tuple <SearchResult, List <Tour> >(searchResult, tours);

            CacheHelper.AddCacheData(hash, result, cacheDependencies.ToList(), Globals.Settings.Cache.LongCacheTimeout);
            return(result);
        }
Example #3
0
        public static ActualizedTour ActualizeTour(this MtSearchDbDataContext searchDc, MtMainDbDataContext mainDc, SftWebDbDataContext sftDc, long offerId, int currencyId, out string hash)
        {
            ActualizedTour result;

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

            string hashOut;
            var    searchResult = searchDc.GetSearchResult(mainDc, sftDc, offerId, currencyId, out hashOut);
            var    tour         = searchDc.ConvertSearchItemsToTours(mainDc, searchResult.SearchItems, currencyId);

            if (tour.Count == 0)
            {
                throw new ApplicationException(MethodBase.GetCurrentMethod().Name +
                                               ". Данных по цене в БД не найдено. Параметры: " + String.Format("{0}_{1}", offerId, currencyId));
            }

            string rateCode = searchDc.GetRateCodeByKey(currencyId);

            var cacheDependencies = new List <string> {
                hashOut
            };

            result = new ActualizedTour
            {
                FewBusinessTicketsDpt = tour[0].FewTicketsDptB,
                FewBusinessTicketsRtn = tour[0].FewTicketsRtnB,
                FewEconomTicketsDpt   = tour[0].FewTicketsDptY,
                FewEconomTicketsRtn   = tour[0].FewTicketsRtnY,
                FewPlacesInHotel      = tour[0].FewPlacesInHotel,
                TicketsIsIncluded     = tour[0].TicketsIncluded,
                HasBusinessTicketsDpt = tour[0].HasBusinessTicketsDpt,
                HasBusinessTicketsRtn = tour[0].HasBusinessTicketsRtn,
                HasEconomTicketsDpt   = tour[0].HasEconomTicketsDpt,
                HasEconomTicketsRtn   = tour[0].HasEconomTicketsRtn,
                TourUrl = tour[0].TourUrl,
                Price   = tour[0].Price
            };

            var parameters     = new List <MtServiceParams>();
            var commandBuilder = new StringBuilder();

            commandBuilder.AppendLine("select distinct ts_key, ts_svkey, ts_name, ts_day, ts_days, ts_attribute, ts_code, ts_subcode1, ts_subcode2, ts_ctkey, ts_men, ts_oppacketkey, ts_oppartnerkey ");
            commandBuilder.AppendLine("from tp_services ");
            commandBuilder.AppendLine(String.Format("where ts_Key in (select tl_tskey from tp_servicelists where tl_tikey in (select tp_tikey from tp_prices where tp_key = {0})) ", tour[0].OfferId));
            commandBuilder.AppendLine("order by ts_day asc ");

            using (var command = mainDc.Connection.CreateCommand())
            {
                command.CommandText = commandBuilder.ToString();

                mainDc.Connection.Open();
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var pars = new MtServiceParams()
                        {
                            Code      = reader.GetInt32("ts_code"),
                            CtKey     = reader.GetInt32("ts_ctkey"),
                            Day       = reader.GetInt16("ts_day"),
                            Days      = reader.GetInt16("ts_days"),
                            Men       = reader.GetInt16("ts_men"),
                            PkKey     = reader.GetInt32("ts_oppacketkey"),
                            PrKey     = reader.GetInt32("ts_oppartnerkey"),
                            SubCode1  = reader.GetInt32("ts_subcode1"),
                            SubCode2  = reader.GetInt32("ts_subcode2"),
                            SvKey     = reader.GetInt32("ts_svkey"),
                            Key       = reader.GetInt32("ts_key"),
                            Name      = reader.GetString("ts_name"),
                            Attribute = reader.GetInt32("ts_attribute")
                        };
                        parameters.Add(pars);
                    }
                }
                mainDc.Connection.Close();
            }


            foreach (var pars in parameters)
            {
                var type = Converters.ServiceClassToServiceType(pars.SvKey, pars.Day);
                if (type == ServiceType.Undefined)
                {
                    continue;
                }

                var service = new Service
                {
                    Id          = pars.Key,
                    Description = String.Empty,
                    Name        = pars.Name,
                    IsIncluded  = (pars.Attribute & (int)ServiceAttribute.NotCalculate) != (int)ServiceAttribute.NotCalculate,
                    Type        = type
                };

                if (!service.IsIncluded)
                {
                    var brutto = mainDc.GetServiceCost(pars.SvKey, pars.Code, pars.SubCode1, pars.SubCode2, pars.PrKey,
                                                       pars.PkKey, searchResult.SearchItems[0].Date.AddDays(pars.Day - 1), pars.Days, rateCode, pars.Men, out hashOut);
                    if (brutto.HasValue)
                    {
                        service.Surcharge = (int)brutto;
                    }
                    else
                    {
                        service.Surcharge = 0;
                    }

                    cacheDependencies.Add(hashOut);
                }

                FlightPlainInfo  flightInfo       = null;
                QuotaStatePlaces quotaStatePlaces = null;
                // услуга - перелет туда и в поиске у нас есть о нем информация
                if (type == ServiceType.DptTransport && pars.SubCode2 == Globals.Settings.HomeCityKey && searchResult.SearchItems[0].FlightCalcInfo.CharterKey.HasValue)
                {
                    service.FlightClass = Converters.CharterClassToFlightClass(pars.SubCode1);

                    switch (service.FlightClass)
                    {
                    case FlightClass.Econom:
                        quotaStatePlaces = searchResult.SearchItems[0].DirectFlightsInfo[0].QuotaState;
                        break;

                    case FlightClass.Business:
                        quotaStatePlaces = searchResult.SearchItems[0].DirectFlightsInfo[1].QuotaState;
                        break;
                    }
                    if (quotaStatePlaces != null)
                    {
                        service.FlightAvailability = Converters.QuotaStateToQuotaAvailability(quotaStatePlaces.QuotaState);
                        if (quotaStatePlaces.QuotaState == QuotesStates.Small)
                        {
                            service.FlightPlacesCount = (int)quotaStatePlaces.Places;
                        }
                    }

                    if (searchResult.SearchItems[0].DirectFlightsInfo.Count > 0)
                    {
                        service.FlightStartDateTime = searchResult.SearchItems[0].DirectFlightsInfo[0].FlightDateTimeFrom;
                        service.FlightEndDateTime   = searchResult.SearchItems[0].DirectFlightsInfo[0].FlightDateTimeTo;
                    }

                    flightInfo = searchResult.SearchItems[0].DirectFlightsInfo[0];
                }
                else if (type == ServiceType.RtnTransport && pars.CtKey == Globals.Settings.HomeCityKey && searchResult.SearchItems[0].FlightCalcInfo.BackCharterKey.HasValue)
                {
                    service.FlightClass = Converters.CharterClassToFlightClass(pars.SubCode1);

                    switch (service.FlightClass)
                    {
                    case FlightClass.Econom:
                        quotaStatePlaces = searchResult.SearchItems[0].BackFlightsInfo[0].QuotaState;
                        break;

                    case FlightClass.Business:
                        quotaStatePlaces = searchResult.SearchItems[0].BackFlightsInfo[1].QuotaState;
                        break;
                    }

                    if (searchResult.SearchItems[0].BackFlightsInfo.Count > 0)
                    {
                        service.FlightStartDateTime = searchResult.SearchItems[0].BackFlightsInfo[0].FlightDateTimeFrom;
                        service.FlightEndDateTime   = searchResult.SearchItems[0].BackFlightsInfo[0].FlightDateTimeTo;
                    }

                    flightInfo = searchResult.SearchItems[0].BackFlightsInfo[0];
                }

                if (quotaStatePlaces != null)
                {
                    service.FlightAvailability = Converters.QuotaStateToQuotaAvailability(quotaStatePlaces.QuotaState);
                    if (quotaStatePlaces.QuotaState == QuotesStates.Small)
                    {
                        service.FlightPlacesCount = (int)quotaStatePlaces.Places;
                    }
                }

                if (flightInfo != null)
                {
                    service.FlightAirportFrom = flightInfo.AirportFrom;
                    service.FlightAirportTo   = flightInfo.AirportTo;
                    service.FlightNum         = flightInfo.AirlineCode + " " + flightInfo.FlightNumber;
                    service.FlightAirline     = flightInfo.AirlineCode;
                    service.FlightAircraft    = flightInfo.AircraftCode;
                }
                result.Services.Add(service);
            }

            foreach (var service in result.Services)
            {
                int compId = 0;
                switch (service.Type)
                {
                case ServiceType.DptTransport:
                {
                    var service1 = service;
                    compId = result.Services.Where(s => s.Type == ServiceType.RtnTransport &&
                                                   s.FlightAirportFrom == service1.FlightAirportTo &&
                                                   s.FlightAirportTo == service1.FlightAirportFrom)
                             .Select(s => s.Id)
                             .SingleOrDefault();
                }
                break;

                case ServiceType.RtnTransport:
                {
                    var service1 = service;
                    compId = result.Services.Where(s => s.Type == ServiceType.DptTransport &&
                                                   s.FlightAirportFrom == service1.FlightAirportTo &&
                                                   s.FlightAirportTo == service1.FlightAirportFrom)
                             .Select(s => s.Id)
                             .SingleOrDefault();
                }
                break;
                }
                service.FlightCompatibleIds = compId != 0 ? compId.ToString() : String.Empty;
            }

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