Example #1
0
        public void CheckHotelQuotes_SmallQuotaState()
        {
            using (var searchDc = new MtSearchDbDataContext())
            {
                string hash;

                const ServiceClass serviceClass = ServiceClass.Hotel;
                const int          code         = 19730;
                const int          subCode1     = 2;
                int?      subCode2        = 32;
                const int partnerKey      = 6732;
                var       serviceDateFrom = new DateTime(2014, 04, 27);
                var       serviceDateTo   = new DateTime(2014, 05, 03);
                const int requestedPlaces = 2;

                var result = searchDc.CheckServiceQuota(serviceClass, code, subCode1,
                                                        subCode2, partnerKey, serviceDateFrom,
                                                        serviceDateTo, requestedPlaces, out hash);

                Assert.AreEqual(result, new QuotaStatePlaces
                {
                    IsCheckInQuota = false,
                    Places         = 1,
                    QuotaState     = QuotesStates.Small
                });
            }
        }
Example #2
0
        public void FlightState_No()
        {
            CacheHelper.AddCacheData("GetCharterCityDirection_Charter_1_3812", new Tuple <int, int>(227, 332), 0);
            CacheHelper.AddCacheData(StopAviaExtension.TableName, new List <StopAvia>(), 0);
            //CacheHelper.AddCacheData("GetPlainQuotasObjects_Quota_1_3812_뱢媘원̸ⷪ뉇靊", new List<QuotaPlain>()
            //GetPlainQuotasObjects_Quota_1_3812
            CacheHelper.AddCacheData("GetPlainQuotasObjects_1_3812_뱢媘원̸ⷪ뉇靊", new List <QuotaPlain>()
            {
                new QuotaPlain
                {
                    Busy                     = 180,
                    CheckInPlaces            = 180,
                    CheckInPlacesBusy        = 0,
                    Date                     = new DateTime(2014, 04, 27),
                    Duration                 = String.Empty,
                    IsAllotmentAndCommitment = false,
                    PartnerKey               = 7859,
                    Places                   = 180,
                    QdId                     = 31136542,
                    QoId                     = 112967,
                    Release                  = null,
                    SsId                     = 20152512,
                    SsQdId                   = 31136542,
                    SubCode1                 = 98,
                    SubCode2                 = -1,
                    Type                     = QuotaType.Commitment
                }
            }, 0);

            int?subCode2 = null;

            using (var searchDc = new MtSearchDbDataContext())
            {
                string hash;

                const ServiceClass serviceClass = ServiceClass.Flight;
                const int          code         = 3812;
                const int          subCode1     = 89;
                const int          partnerKey   = 7859;
                var       serviceDateFrom       = new DateTime(2014, 04, 27);
                var       serviceDateTo         = new DateTime(2014, 05, 22);
                const int requestedPlaces       = 2;

                var result = searchDc.CheckServiceQuota(serviceClass, code, subCode1, subCode2, partnerKey, serviceDateFrom,
                                                        serviceDateTo, requestedPlaces, out hash);

                Assert.AreEqual(result.QuotaState, QuotesStates.No);
                Assert.AreEqual(result.Places, (uint)0);

                Assert.AreEqual(result, new QuotaStatePlaces()
                {
                    IsCheckInQuota = false,
                    Places         = 0,
                    QuotaState     = QuotesStates.No
                });
            }
        }
Example #3
0
        /// <summary>
        /// Метод по проверке квот на перелет (можно использовать для вывода информации о перелетах п строке)
        /// </summary>
        /// <param name="dc">Контекст БД</param>
        /// <param name="mainDc">Контекст основной БД</param>
        /// <param name="charterKey">Ключ перелета</param>
        /// <param name="cityKeyFrom">Ключ города вылета</param>
        /// <param name="cityKeyTo">Ключ города прилета</param>
        /// <param name="charterDay">День вылета в туре</param>
        /// <param name="partnerKey">Ключ партнера по перелету</param>
        /// <param name="agentKey">Ключ агентства</param>
        /// <param name="packetKey">Ключ пакета</param>
        /// <param name="tourDate">Дата тура</param>
        /// <param name="linkedDay">День вылета парного перелета</param>
        /// <param name="findFlight">Признак "подбирать или не подбирать" перелет</param>
        /// <param name="flightGroups">Группы перелетов (эконом, бизнес, премиум)</param>
        /// <param name="hash">Хэш кэша</param>
        /// <returns></returns>
        public static Dictionary <int, List <FlightPlainInfo> > GetCharterAllQuota(this MtSearchDbDataContext dc,
                                                                                   MtMainDbDataContext mainDc,
                                                                                   Int32 charterKey, Int32 cityKeyFrom, Int32 cityKeyTo,
                                                                                   Int32 charterDay, int partnerKey, int?agentKey, int packetKey, DateTime tourDate, Int32?linkedDay,
                                                                                   bool findFlight, IDictionary <int, IEnumerable <int> > flightGroups, out string hash)
        {
            var    cacheDependencies = new List <string>();
            string cacheDep;

            hash = String.Format("{0}_{1}_{2}", MethodBase.GetCurrentMethod().Name, charterKey,
                                 CacheHelper.GetCacheKeyHashed(new[]
            {
                cityKeyFrom.ToString(),
                cityKeyTo.ToString(),
                partnerKey.ToString(),
                agentKey.ToString(),
                charterDay.ToString(), packetKey.ToString(), tourDate.ToString("yyyy-MM-dd"), linkedDay.ToString(),
                findFlight.ToString(),
                String.Join("_", flightGroups.Keys),
                String.Join("_", flightGroups.Values)
            }));

            Dictionary <int, List <FlightPlainInfo> > result;

            if ((result = CacheHelper.GetCacheItem <Dictionary <int, List <FlightPlainInfo> > >(hash)) != null)
            {
                return(result);
            }

            var charterDate = tourDate.AddDays(charterDay - 1).Date;

            // в случае, если перелета с ключом charterKey в БД нет, не найдутся ctKeyFrom и ctKeyTo
            // при этом мы возьмем данные, которые стоят в БД - cityKeyFrom и cityKeyTo
            int?ctKeyFrom, ctKeyTo;

            dc.GetCharterCityDirection(charterKey, out ctKeyFrom, out ctKeyTo);
            if (ctKeyFrom.HasValue)
            {
                cityKeyFrom = ctKeyFrom.Value;
            }
            if (ctKeyTo.HasValue)
            {
                cityKeyTo = ctKeyTo.Value;
            }

            result =
                findFlight
                    ? dc.GetAltCharters(mainDc, cityKeyFrom, cityKeyTo, charterDate, packetKey, flightGroups, out cacheDep)
                    : dc.GetAltCharters(mainDc, charterKey, charterDate, packetKey, flightGroups, out cacheDep);
            cacheDependencies.Add(cacheDep);

            foreach (var key in flightGroups.Keys)
            {
                foreach (var flight in result[key])
                {
                    if (dc.IsStopByDrection(cityKeyFrom, cityKeyTo, charterDate,
                                            linkedDay != null ? tourDate.AddDays(linkedDay.Value - 1) : charterDate, out cacheDep))
                    {
                        flight.QuotaState = new QuotaStatePlaces
                        {
                            QuotaState = QuotesStates.No
                        };
                    }
                    else
                    {
                        flight.QuotaState = dc.CheckServiceQuota(ServiceClass.Flight, flight.CharterKey, flight.ClassKey, null, flight.PartnerKey, agentKey, charterDate, linkedDay != null ? tourDate.AddDays(linkedDay.Value - 1) : charterDate, out cacheDep);
                    }
                    cacheDependencies.Add(cacheDep);

                    //if (flightInfo.QuotaState.QuotaState == QuotesStates.Undefined
                    //    || QuotasExtension.OrderderQuotaStates[tempState.QuotaState] > QuotasExtension.OrderderQuotaStates[flightInfo.QuotaState.QuotaState]
                    //    || (tempState.QuotaState == QuotesStates.Small && flightInfo.QuotaState.QuotaState == QuotesStates.Small && tempState.Places > flightInfo.QuotaState.Places))
                    //{
                    //    flightInfo.QuotaState = tempState;
                    //}

                    //if (flightInfo.QuotaState.QuotaState == QuotesStates.Availiable)
                    //    break;
                }
            }


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