Beispiel #1
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);
        }
Beispiel #2
0
        private static List <Tour> ConvertSearchItemsToTours(this MtSearchDbDataContext searchDc, MtMainDbDataContext mainDc, IEnumerable <SearchResultItem> resultItems, int currencyId)
        {
            var result = new List <Tour>(resultItems.Count());

            foreach (var item in resultItems)
            {
                int hotelCategoryKey;
                using (var mainContext = new MtMainDbDataContext())
                {
                    hotelCategoryKey = mainContext.GetAllHotelCats()
                                       .Where(c => c.COH_Name == item.Hotels[0].Stars)
                                       .Select(c => c.COH_Id)
                                       .SingleOrDefault();
                }
                var description = searchDc.GetTourDescription(item.TourKey);
                //todo: убрать ссылку на солвекс, добавить настройку в web.config
                result.Add(new Tour
                {
                    OfferId               = item.PriceKey,
                    TourName              = item.TourName,
                    HotelId               = item.Hotels[0].Key,
                    HotelUrl              = item.Hotels[0].Url,
                    ResortId              = item.Hotels[0].ResortKey,
                    HotelCategoryId       = hotelCategoryKey,
                    MealId                = item.Hotels[0].PansionKey,
                    HtPlaceName           = item.Hotels[0].AccomodationName,
                    RoomTypeName          = item.Hotels[0].RoomCategoryName,
                    TourDate              = item.Date,
                    Nights                = item.DateTourEnd.Subtract(item.Date).Days,
                    Price                 = (int)Math.Round((double)searchDc.GetRateRealCourse(DateTime.Now.Date, searchDc.GetRateKeyByCode(item.RateCode), currencyId) * item.Price),
                    HotelInStop           = (int)Converters.GetHotelQuota(item.Hotels.Select(h => h.QuotaState.QuotaState).ToList()),
                    TicketsIncluded       = (int)Converters.GetTicketsInPrice(item.DirectFlightsInfo.Values.Select(q => q.QuotaState.QuotaState).ToList(), item.BackFlightsInfo.Values.Select(q => q.QuotaState.QuotaState).ToList()),
                    HasEconomTicketsDpt   = (int)Converters.GetCharterQuota(item.DirectFlightsInfo.Count > 0 ? item.DirectFlightsInfo[0].QuotaState.QuotaState : QuotesStates.None),
                    HasEconomTicketsRtn   = (int)Converters.GetCharterQuota(item.DirectFlightsInfo.Count > 0 ? item.BackFlightsInfo[0].QuotaState.QuotaState : QuotesStates.None),
                    HasBusinessTicketsDpt = (int)Converters.GetCharterQuota(item.DirectFlightsInfo.Count > 1 ? item.DirectFlightsInfo[1].QuotaState.QuotaState : QuotesStates.None),
                    HasBusinessTicketsRtn = (int)Converters.GetCharterQuota(item.DirectFlightsInfo.Count > 1 ? item.BackFlightsInfo[1].QuotaState.QuotaState : QuotesStates.None),
                    TourUrl               = String.Format("http://online.solvex.travel/SimpleBasket.aspx?priceKey={0}&date={1}", item.PriceKey, item.Date.ToString("yyyy-MM-dd")),
                    SpoUrl                = item.TourUrl,
                    FewPlacesInHotel      = Converters.IsFewPlaces(item.Hotels.Select(q => q.QuotaState).ToList()),
                    FewTicketsDptY        = item.DirectFlightsInfo.Count > 0 ? Converters.IsFewPlaces(new List <QuotaStatePlaces>()
                    {
                        item.DirectFlightsInfo[0].QuotaState
                    }) : null,
                    FewTicketsDptB = item.DirectFlightsInfo.Count > 1 ? Converters.IsFewPlaces(new List <QuotaStatePlaces>()
                    {
                        item.DirectFlightsInfo[1].QuotaState
                    }) : null,
                    FewTicketsRtnY = item.DirectFlightsInfo.Count > 0 ? Converters.IsFewPlaces(new List <QuotaStatePlaces>()
                    {
                        item.BackFlightsInfo[0].QuotaState
                    }) : null,
                    FewTicketsRtnB = item.DirectFlightsInfo.Count > 1 ? Converters.IsFewPlaces(new List <QuotaStatePlaces>()
                    {
                        item.BackFlightsInfo[1].QuotaState
                    }) : null,
                    Flags                 = item.Hotels.Count > 1 ? (long)Flags.Combined : 0 | (long)Flags.EarlyBooking,
                    Description           = description,
                    EarlyBookingValidTill = item.GetTourValidTo()
                });
            }

            return(result);
        }