Exemple #1
0
        /// <summary>
        /// Get base adult/child rate plan from BaseRatePlanOccupantRate table
        /// </summary>
        /// <param name="baseRatePlanOccupantRate">BaseRatePlanOccupantRate</param>
        /// <param name="baseRatePlan">BaseRatePlan</param>
        /// <param name="baseRatePlanRate">RatePlanRate</param>
        /// <param name="roomTypeName">Name for RoomType</param>
        /// <param name="IsAdult">True if is Adult rate plan</param>
        /// <returns>Adult RatePlan</returns>
        private VariantRatePlan GetOccupantRatePlan(BaseRatePlanOccupantRate baseRatePlanOccupantRate, BaseRatePlan baseRatePlan, RatePlanRate baseRatePlanRate, string roomTypeName, bool IsAdult, OccupancyRateType occupancyRateType, bool fetchDateRanges = false)
        {
            var occupantRatePlan = CreateVariantFromBase(baseRatePlan, string.Concat(roomTypeName, " - ", baseRatePlanRate.PeriodId));

            //override the rates from the base with occupant rates
            occupantRatePlan.Rates = IsAdult ? GetAdultRate(baseRatePlanOccupantRate, baseRatePlanRate) : GetChildRate(baseRatePlanOccupantRate, baseRatePlanRate);
            occupantRatePlan.Period = baseRatePlanOccupantRate.Period;
            occupantRatePlan.PeriodId = baseRatePlanOccupantRate.PeriodId;//baseRatePlanOccupantRate.Period == null ? 0 : baseRatePlanOccupantRate.Period.Id;
            occupantRatePlan.RatePlanType = new RatePlanType() { Type = RatePlanTypeEnum.Base };
            occupantRatePlan.Rates.OccupancyRateType = occupancyRateType;

            if (fetchDateRanges &&
                occupantRatePlan.Period != null && occupantRatePlan.Period.Id != default(int) &&
                (occupantRatePlan.Period.PeriodDateRanges == null || !occupantRatePlan.Period.PeriodDateRanges.Any()))
            {
                occupantRatePlan.Period.PeriodDateRanges = periodDateRangeDao.GetAllByPeriodId(occupantRatePlan.Period.Id);
            }

            return occupantRatePlan;
        }
Exemple #2
0
        /// <summary>
        /// Get child rates for a base rate plan
        /// </summary>
        /// <returns>Collection of RatePlanRate</returns>
        private RatePlanRate GetChildRate(BaseRatePlanOccupantRate baseRatePlanOccupantRate, RatePlanRate baseRatePlanRate)
        {
            return new RatePlanRate
            {
                Id = baseRatePlanOccupantRate.Id,
                BusinessId = baseRatePlanOccupantRate.BusinessId,
                RatePlanId = baseRatePlanOccupantRate.RatePlanId,
                PeriodId = baseRatePlanOccupantRate.PeriodId,
                MonRate = baseRatePlanOccupantRate.MonChildRate,
                MonMinStay = baseRatePlanRate.MonMinStay,
                TueRate = baseRatePlanOccupantRate.TueChildRate,
                TueMinStay = baseRatePlanRate.TueMinStay,
                WedRate = baseRatePlanOccupantRate.WedChildRate,
                WedMinStay = baseRatePlanRate.WedMinStay,
                ThuRate = baseRatePlanOccupantRate.ThuChildRate,
                ThuMinStay = baseRatePlanRate.ThuMinStay,
                FriRate = baseRatePlanOccupantRate.FriChildRate,
                FriMinStay = baseRatePlanRate.FriMinStay,
                SatRate = baseRatePlanOccupantRate.SatChildRate,
                SatMinStay = baseRatePlanRate.SatMinStay,
                SunRate = baseRatePlanOccupantRate.SunChildRate,
                SunMinStay = baseRatePlanRate.SunMinStay
            };

        }
Exemple #3
0
        /// <summary>
        /// Create a collection of default VariantRataPlans for PerPerson pricing
        /// </summary>
        /// <param name="baseRatePlan">BaseRatePlan</param>
        /// <param name="evergreenRatePlanRate">Evergreen RatePlanRate</param>
        /// <param name="baseRatePlanRates">Base RatePlanRates</param>
        /// <param name="businessPeriods">Business Periods</param>
        /// <param name="cultureCode">CultureCode</param>
        /// <returns>Collection of VariantRatePlans</returns>
        private List<VariantRatePlan> GetDefaultVariantPerPersonRatePlans(BaseRatePlan baseRatePlan, RatePlanRate evergreenRatePlanRate, List<BaseRatePlanOccupantRate> baseRatePlanRates, List<Period> businessPeriods, string cultureCode)
        {
            var defaultVariantRatePlans = new List<VariantRatePlan>();
            var instantiatedRatePlan = CreateVariantFromBase(baseRatePlan, string.Empty);
            instantiatedRatePlan.Id = 0;
            instantiatedRatePlan.VariantRatePlanRateId = 0;
            instantiatedRatePlan.VariantAmount = 0;
            instantiatedRatePlan.ApplicableDays = Constants.FULL_AVAILABILITY;
            instantiatedRatePlan.UseOccupancyRates = baseRatePlan.UseOccupancyRates;
            // set this variant rate plan period to evergreen period
            SetVariantDefaultPeriod(instantiatedRatePlan, cultureCode);
            // set to evergreen rates if exist
            RatePlanRate variantRatePlanRates = evergreenRatePlanRate == null
                                                   ? GetBaseRackRates(baseRatePlan)
                                                   : CloneRatePlanRates(evergreenRatePlanRate);
            instantiatedRatePlan.Rates = variantRatePlanRates;
            instantiatedRatePlan.IsSelectedSeason = false;
            instantiatedRatePlan.VariantType = new VariantType() { Type = VariantTypeEnum.Amount };
            instantiatedRatePlan.RatePlanType = new RatePlanType() { Type = RatePlanTypeEnum.Variant };
            instantiatedRatePlan.UseOccupancyRates = true;
            instantiatedRatePlan.Rates.OccupancyRateType = OccupancyRateType.Unknown;
            defaultVariantRatePlans.Add(instantiatedRatePlan);

            var adultInstantiatedRatePlan = GetDefaultOccupantVariantPerPersonRatePlan(instantiatedRatePlan, cultureCode, OccupancyRateType.Adult);
            defaultVariantRatePlans.Add(adultInstantiatedRatePlan);
            var childInstantiatedRatePlan = GetDefaultOccupantVariantPerPersonRatePlan(instantiatedRatePlan, cultureCode, OccupancyRateType.Child);
            defaultVariantRatePlans.Add(childInstantiatedRatePlan);
           
            // clone evergreen variant for later use
            var evergreenRatePlan = CloneVariantRatePlan(instantiatedRatePlan);

            // create variants for business periods that have not been associated with a variant rate plan
            foreach (var period in businessPeriods)
            {
                VariantRatePlan instantiatedPlan = CloneVariantRatePlan(evergreenRatePlan);
                instantiatedPlan.VariantType = new VariantType() { Type = VariantTypeEnum.Amount };
                // as this is a created on the fly variant based on an existing one, there would not be a VariantRatePlanRate record
                instantiatedPlan.VariantRatePlanRateId = 0;
                instantiatedRatePlan.ApplicableDays = Constants.FULL_AVAILABILITY;
                instantiatedRatePlan.IsActive = true;
                instantiatedPlan.Periods = CreateVariantRatePlanPeriods(period);
                var variantRatePlanRate = baseRatePlanRates.Find(brpr => brpr.PeriodId == period.Id);
                RatePlanRate variantRatePlanRateForAllPeriods = variantRatePlanRate != null ? CloneRatePlanRates(variantRatePlanRate) : GetDefaultVariantEvergreenBaseRates(instantiatedPlan);
                SetVariantRates(variantRatePlanRateForAllPeriods, instantiatedPlan);
                // as this variant is artificially created, set to false
                instantiatedPlan.IsSelectedSeason = false;
                instantiatedPlan.RatePlanType = new RatePlanType() { Type = RatePlanTypeEnum.Variant };
                instantiatedRatePlan.UseOccupancyRates = true;
                instantiatedRatePlan.Rates.OccupancyRateType = OccupancyRateType.Unknown; ;
                defaultVariantRatePlans.Add(instantiatedPlan);

                var adultInstantiatedVariantRatePlan  = GetDefaultOccupantVariantPerPersonRatePlan(instantiatedPlan, cultureCode, OccupancyRateType.Adult);
                adultInstantiatedVariantRatePlan.Periods = CreateVariantRatePlanPeriods(period);
                defaultVariantRatePlans.Add(adultInstantiatedVariantRatePlan);

                var childInstantiatedVariantRatePlan = GetDefaultOccupantVariantPerPersonRatePlan(instantiatedPlan, cultureCode, OccupancyRateType.Child);
                childInstantiatedVariantRatePlan.Periods = CreateVariantRatePlanPeriods(period);
                defaultVariantRatePlans.Add(childInstantiatedVariantRatePlan);

                defaultVariantRatePlans.ForEach(x=> x.IsDefault = true);

            }
            return defaultVariantRatePlans;
        }
Exemple #4
0
 /// <summary>
 ///  Create non evergreen occupant rate plan from base rate plan
 /// </summary>
 /// <param name="baseRatePlan">BaseRatePlan</param>
 /// <param name="roomTypeName">>RoomType name</param>
 /// <param name="ratePlanRate">RatePlanRate</param>
 /// <param name="period">Period</param>
 /// <param name="occupancyRateType">OccupancyRateType</param>
 /// <returns>RatePlan</returns>
 private VariantRatePlan CreateNonEvergreenOccupantRatePlan(BaseRatePlan baseRatePlan, string roomTypeName, RatePlanRate ratePlanRate, Period period, OccupancyRateType occupancyRateType)
 {
     var occupantRatePlan = CreateVariantFromBase(baseRatePlan, roomTypeName);
     occupantRatePlan.Id = 0;
     occupantRatePlan.RatePlanType = new RatePlanType { Type = RatePlanTypeEnum.Base };
     occupantRatePlan.Period = period;
     occupantRatePlan.PeriodId = period.Id;
     occupantRatePlan.Rates = GetNulRates(occupantRatePlan);
     GetDefaultVariantEvergreenBaseRates(occupantRatePlan);
     occupantRatePlan.Rates.Id = 0;
     occupantRatePlan.Rates.RatePlanId = baseRatePlan.Id;
     occupantRatePlan.Rates.OccupancyRateType = occupancyRateType;
     occupantRatePlan.UseOccupancyRates = true;
     return occupantRatePlan;
 }
Exemple #5
0
            public void ModifyRatePlanRateIsSuccessful()
            {
                // Arrange
                var eventTrackingManager = new Mock<IEventTrackingManager>();
                var ratePlanRateDao = new Mock<IBaseRatePlanRatesDao>();

                RatePlanManager ratePlanManager = new RatePlanManager
                {
                    RatePlanRateDao = ratePlanRateDao.Object,
                    EventTrackingManager = eventTrackingManager.Object
                };

                const int RATE_PLAN_ID = 1;
                const long BUSINESS_ID = 1;
                const int RATE_PLAN_RATE_ID = 5;

                var ratePlanRate = new RatePlanRate { BusinessId = BUSINESS_ID, Id = RATE_PLAN_RATE_ID, RatePlanId = RATE_PLAN_ID };

                ratePlanRateDao.Setup(rp => rp.Modify(It.Is<RatePlanRate>(rpr => rpr.Id == RATE_PLAN_RATE_ID && rpr.BusinessId == BUSINESS_ID && rpr.RatePlanId == RATE_PLAN_ID)));

                eventTrackingManager.Setup(be => be.CreateBusinessEventAsync(BUSINESS_ID, BusinessEventTypesEnum.RatePlanRateModified, ratePlanRate.Id.ToString(CultureInfo.InvariantCulture), null));

                // Act
                ratePlanManager.ModifyRatePlanRates(ratePlanRate);

                // Assert
                ratePlanRateDao.VerifyAll();
                eventTrackingManager.VerifyAll();
            }
Exemple #6
0
            public void CreateEditBaseRatePlanRatesForEvergreenRatePlanExpectRatePlanToBeCreated()
            {
                // Arrange
                const int RATE_PLAN_ID = 1;
                const long BUSINESS_ID = 1;

                var eventTrackingManager = new Mock<IEventTrackingManager>();
                var ratePlanRateDao = new Mock<IBaseRatePlanRatesDao>();
                RatePlanManager ratePlanManager = new RatePlanManager
                {
                    EventTrackingManager = eventTrackingManager.Object,
                    RatePlanRateDao = ratePlanRateDao.Object
                };

                var ratePlanRate = new RatePlanRate { BusinessId = BUSINESS_ID, Id = 0, RatePlanId = RATE_PLAN_ID, PeriodId = null, OccupancyRateType = OccupancyRateType.Base};
                var ratePlanRates = new List<RatePlanRate>() { ratePlanRate };
                ratePlanRateDao.Setup(rp => rp.Create(It.Is<RatePlanRate>(rpr => rpr.Id == 0 && rpr.BusinessId == BUSINESS_ID && rpr.RatePlanId == RATE_PLAN_ID)));

                eventTrackingManager.Setup(be => be.CreateBusinessEventAsync(BUSINESS_ID, BusinessEventTypesEnum.RatePlanAdded, RATE_PLAN_ID.ToString(CultureInfo.InvariantCulture), null));

                // Act
                ratePlanManager.CreateEditBaseRatePlanRates(ratePlanRates);

                // Assert
                ratePlanRateDao.VerifyAll();
                eventTrackingManager.VerifyAll();
            }
Exemple #7
0
 /// <summary>
 /// Validates if the prices for all rates in the list are set to 0
 /// </summary>
 /// <param name="rate">Rates</param>
 private static void CheckIfAllRatesHavePriceZero(RatePlanRate rate)
 {
     if (rate.MonRate == default(decimal) && rate.TueRate == default(decimal) && rate.WedRate == default(decimal) && rate.ThuRate == default(decimal) &&
         rate.FriRate == default(decimal) && rate.SatRate == default(decimal) && rate.SunRate == default(decimal))
     {
         throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30089, "RoomTypeManager.CheckIfAllRatesHavePriceZero", arguments: new object[] { rate }));
     }
 }
Exemple #8
0
            public void CreateBaseRatePlanIsSuccessful()
            {
                // Arrange
                var ratePlanRateDao = new Mock<IBaseRatePlanRatesDao>();
                var eventTrackingManager = new Mock<IEventTrackingManager>();
                var ratePlanDao = new Mock<IBaseRatePlanDao>();
                var ratePlanManager = new RatePlanManager { RatePlanRateDao = ratePlanRateDao.Object, 
                                                            EventTrackingManager = eventTrackingManager.Object, 
                                                            BaseRatePlanDao = ratePlanDao.Object };
                
                const int RATE_PLAN_ID = 1;
                const long BUSINESS_ID = 1;
                var rates = new RatePlanRate
                                {
                                    RatePlanId = RATE_PLAN_ID,
                                    MonMinStay = 1,
                                    MonRate = new decimal(10),
                                    TueMinStay= 1,
                                    TueRate = new decimal(10),
                                    WedMinStay = 1,
                                    WedRate = new decimal(10),
                                    ThuMinStay = 1,
                                    ThuRate = new decimal(10),
                                    FriMinStay = 1,
                                    FriRate = new decimal(10),
                                    SatMinStay = 1,
                                    SatRate = new decimal(10),
                                    SunMinStay = 1,
                                    SunRate = new decimal(10),
                               };

                var ratePlan = new BaseRatePlan { BusinessId = BUSINESS_ID, Rates = rates, RatePlanType = new RatePlanType { Type = RatePlanTypeEnum.Base } };

                ratePlanDao.Setup(rp => rp.Create(ratePlan)).Callback(delegate { ratePlan.Id = RATE_PLAN_ID; });

                int id = 2;

                ratePlanRateDao.Setup(x => x.Create(rates)).Callback(delegate { rates.Id = id; });
                eventTrackingManager.Setup(
                    be =>
                    be.CreateBusinessEventAsync(BUSINESS_ID, BusinessEventTypesEnum.RatePlanAdded,
                                           RATE_PLAN_ID.ToString(CultureInfo.InvariantCulture), null));

                eventTrackingManager.Setup(
                    be =>
                    be.CreateBusinessEventAsync(BUSINESS_ID, BusinessEventTypesEnum.RatePlanRateAdded,
                                           id.ToString(CultureInfo.InvariantCulture), null));

                // Act
                ratePlanManager.CreateBaseRatePlan(ratePlan);

                // Assert
                ratePlanRateDao.VerifyAll();
                eventTrackingManager.VerifyAll();
                ratePlanDao.VerifyAll();
            }
Exemple #9
0
        /// <summary>
        /// Create RatePlanRate
        /// </summary>
        /// <param name="ratePlanRates">RatePlan to change</param>
        public void Create(RatePlanRate ratePlanRates)
        {
            const string SQL_STATEMENT = @"
                INSERT INTO Pricing.BaseRatePlanRates
                (
                        RatePlanId,
                        PeriodId,
                        MonRate,
                        MonMinStay, 
                        TueRate,
                        TueMinStay,
                        WedRate,
                        WedMinStay,
                        ThuRate,
                        ThuMinStay,
                        FriRate,
                        FriMinStay,
                        SatRate,
                        SatMinStay,
                        SunRate,
                        SunMinStay,
                        UpdatedByUserId
                )
                VALUES
                (
                        @RatePlanId,
                        @PeriodId,
                        @MonRate,
                        @MonMinStay,
                        @TueRate,
                        @TueMinStay,
                        @WedRate,
                        @WedMinStay,
                        @ThuRate,
                        @ThuMinStay,
                        @FriRate,
                        @FriMinStay,
                        @SatRate,
                        @SatMinStay,
                        @SunRate,
                        @SunMinStay,
                        @UpdatedByUserId
                )
                SELECT @Id = SCOPE_IDENTITY()";

            var parameters = new List<SqlParameter>
            {
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.RatePlanId, ratePlanRates.RatePlanId),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.PeriodId, ratePlanRates.PeriodId),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.MonRate, ratePlanRates.MonRate),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.MonMinStay, ratePlanRates.MonMinStay),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.TueRate, ratePlanRates.TueRate),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.TueMinStay, ratePlanRates.TueMinStay),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.WedRate, ratePlanRates.WedRate),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.WedMinStay, ratePlanRates.WedMinStay),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.ThuRate, ratePlanRates.ThuRate),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.ThuMinStay, ratePlanRates.ThuMinStay),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.FriRate, ratePlanRates.FriRate),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.FriMinStay, ratePlanRates.FriMinStay),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.SatRate, ratePlanRates.SatRate),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.SatMinStay, ratePlanRates.SatMinStay),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.SunRate, ratePlanRates.SunRate),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.SunMinStay, ratePlanRates.SunMinStay)
            };

            // Add auditing parameters
            AuditFieldsHelper.PopulateAuditFields(parameters);

            SqlParameter outputKey;
            parameters.Add(outputKey = DbHelper.CreateParameterOut<int>(RatePlanRateMapper.Parameters.Id, SqlDbType.Int));

            DbHelper.ExecuteNonQueryCommand(SQL_STATEMENT, parameters: parameters);
            ratePlanRates.Id = DbHelper.ParameterValue<int>(outputKey);
        }
Exemple #10
0
        /// <summary>
        /// Create copy of the specified RatePlanRate
        /// </summary>
        /// <param name="ratePlanRate">RatePlanRate</param>
        /// <returns>Return copy of RatePlanRate</returns>
        private static RatePlanRate CloneRatePlanRates(RatePlanRate ratePlanRate)
        {
            if (ratePlanRate == null)
            {
                throw new ArgumentNullException("ratePlanRate");
            }


            return new RatePlanRate
            {
                MonRate = ratePlanRate.MonRate,
                MonMinStay = ratePlanRate.MonMinStay,
                TueRate = ratePlanRate.TueRate,
                TueMinStay = ratePlanRate.TueMinStay,
                WedRate = ratePlanRate.WedRate,
                WedMinStay = ratePlanRate.WedMinStay,
                ThuRate = ratePlanRate.ThuRate,
                ThuMinStay = ratePlanRate.ThuMinStay,
                FriRate = ratePlanRate.FriRate,
                FriMinStay = ratePlanRate.FriMinStay,
                SatRate = ratePlanRate.SatRate,
                SatMinStay = ratePlanRate.SatMinStay,
                SunRate = ratePlanRate.SunRate,
                SunMinStay = ratePlanRate.SunMinStay,
                RatePlanId = ratePlanRate.RatePlanId
            };
        }
Exemple #11
0
        /// <summary>
        /// Modify RatePlanRate
        /// </summary>
        /// <param name="ratePlanRate">RatePlan rate to change</param>
        public void Modify(RatePlanRate ratePlanRate)
        {
            const string SQL_STATEMENT = @"
                UPDATE Pricing.BaseRatePlanRates
                set 
                        RatePlanId = @RatePlanId,
                        PeriodId = @PeriodId,
                        MonRate = @MonRate,
                        MonMinStay = @MonMinStay,
                        TueRate = @TueRate,
                        TueMinStay = @TueMinStay,
                        WedRate = @WedRate,
                        WedMinStay = @WedMinStay,
                        ThuRate = @ThuRate,
                        ThuMinStay = @ThuMinStay,
                        FriRate = @FriRate,
                        FriMinStay = @FriMinStay,
                        SatRate = @SatRate,
                        SatMinStay = @SatMinStay,
                        SunRate = @SunRate,
                        SunMinStay = @SunMinStay,
                        UpdatedByUserId = @UpdatedByUserId
                where
                        Id = @Id";

            var parameters = new List<SqlParameter>
            {
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.Id, ratePlanRate.Id),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.RatePlanId, ratePlanRate.RatePlanId),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.PeriodId, ratePlanRate.PeriodId),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.MonRate, ratePlanRate.MonRate),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.MonMinStay, ratePlanRate.MonMinStay),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.TueRate, ratePlanRate.TueRate),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.TueMinStay, ratePlanRate.TueMinStay),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.WedRate, ratePlanRate.WedRate),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.WedMinStay, ratePlanRate.WedMinStay),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.ThuRate, ratePlanRate.ThuRate),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.ThuMinStay, ratePlanRate.ThuMinStay),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.FriRate, ratePlanRate.FriRate),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.FriMinStay, ratePlanRate.FriMinStay),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.SatRate, ratePlanRate.SatRate),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.SatMinStay, ratePlanRate.SatMinStay),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.SunRate, ratePlanRate.SunRate),
                DbHelper.CreateParameter(RatePlanRateMapper.Parameters.SunMinStay, ratePlanRate.SunMinStay)
            };

            // Add auditing parameters
            AuditFieldsHelper.PopulateAuditFields(parameters);

            DbHelper.ExecuteNonQueryCommand(SQL_STATEMENT, parameters: parameters);
        }
Exemple #12
0
            public void CreateEditVariantRatePlansWithInvalidVariantAmountThrowsException()
            {
                // Arrange
                const int variantRatePlanId = 1;
                const int variantRatePlanRateId = 0;
                const int roomTypeId = 1;
                const long businessId = 1;
                const int baseRatePlanId = 1;
                const decimal rackRate = 30;
                const decimal rate = 40;
                const decimal variantRate = -50;

                var baseRatePlanDao = new Mock<IBaseRatePlanDao>();
                var baseRatePlanRatesDao = new Mock<IBaseRatePlanRatesDao>();

                var variantRatePlan = new VariantRatePlan { Id = variantRatePlanId, VariantRatePlanRateId = variantRatePlanRateId, RoomTypeId = roomTypeId, BusinessId = businessId, VariantType = new VariantType { Type = VariantTypeEnum.Amount }, VariantAmount = variantRate };
                var baseRatePlan = new BaseRatePlan { Id = baseRatePlanId, SellAtRackRate = true, RackRate = rackRate };
                var ratePlanRate = new RatePlanRate { MonRate = rate, TueRate = rate, WedRate = rate, ThuRate = rate, FriRate = rate, SatRate = rate, SunRate = rate };

                var ratePlanManager = new RatePlanManager
                {
                    BaseRatePlanDao = baseRatePlanDao.Object,
                    BaseRatePlanRatesDao = baseRatePlanRatesDao.Object
                };

                baseRatePlanDao.Setup(brp => brp.GetByRoomTypeId(roomTypeId, businessId, string.Empty)).Returns(baseRatePlan);
                baseRatePlanRatesDao.Setup(brp => brp.GetByRatePlanId(baseRatePlanId)).Returns(new List<RatePlanRate> { ratePlanRate });
                
                try
                {
                    // Act
                    ratePlanManager.CreateEditVariantRatePlans(new List<VariantRatePlan> { variantRatePlan });

                    // Assert
                    Assert.Fail("Validation exception was not thrown");
                }
                catch (ValidationException vex)
                {
                    Assert.AreEqual(Errors.SRVEX30142.ToString(), vex.Code, "Incorrect validation exception was thrown");
                }
            }
Exemple #13
0
            public void CreateEditVariantRatePlansForExistingRatePlanAndSelectedSeasonExpectRatePlanModified()
            {
                // Arrange
                const int variantRatePlanId = 1;
                const int variantRatePlanRateId = 0;
                const int roomTypeId = 1;
                const long businessId = 1;
                const int baseRatePlanId = 1;
                const decimal rackRate = 30;
                const decimal rate = 40;

                var eventTrackingManager = new Mock<IEventTrackingManager>();
                var variantRatePlanDao = new Mock<IVariantRatePlanDao>();
                var baseRatePlanDao = new Mock<IBaseRatePlanDao>();
                var baseRatePlanRatesDao = new Mock<IBaseRatePlanRatesDao>();
                var promotionManagerMock = new Mock<IPromotionManager>();

                var variantRatePlan = new VariantRatePlan { Id = variantRatePlanId, VariantRatePlanRateId = variantRatePlanRateId, RoomTypeId = roomTypeId, BusinessId = businessId, VariantType = new VariantType { Type = VariantTypeEnum.Percentage } };
                var baseRatePlan = new BaseRatePlan { Id = baseRatePlanId, SellAtRackRate = true, RackRate = rackRate };
                var ratePlanRate = new RatePlanRate { MonRate = rate, TueRate = rate, WedRate = rate, ThuRate = rate, FriRate = rate, SatRate = rate, SunRate = rate };
                
                var ratePlanManager = new RatePlanManager
                    {
                        EventTrackingManager = eventTrackingManager.Object,
                        VariantRatePlanDao = variantRatePlanDao.Object,
                        BaseRatePlanDao = baseRatePlanDao.Object,
                        BaseRatePlanRatesDao = baseRatePlanRatesDao.Object,
                        PromotionManager = promotionManagerMock.Object
                    };

                baseRatePlanDao.Setup(brp => brp.GetByRoomTypeId(roomTypeId, businessId, string.Empty)).Returns(baseRatePlan);
                baseRatePlanRatesDao.Setup(brp => brp.GetByRatePlanId(baseRatePlanId)).Returns(new List<RatePlanRate> { ratePlanRate });
                promotionManagerMock.Setup(pr => pr.UpsertPromotionRatePlanLinks(It.IsAny<RatePlan>()));

                variantRatePlanDao.Setup(vrp => vrp.Modify(variantRatePlan));

                eventTrackingManager.Setup(e => e.CreateBusinessEventAsync(It.IsAny<long>(), It.IsAny<BusinessEventTypesEnum>(), It.IsAny<string>(), null));
               
                // Act 
                ratePlanManager.CreateEditVariantRatePlans(new List<VariantRatePlan> { variantRatePlan });

                // Assert
                variantRatePlanDao.VerifyAll();
                eventTrackingManager.Verify(e => e.CreateBusinessEventAsync(It.IsAny<long>(), BusinessEventTypesEnum.VariantRatePlanModified, It.IsAny<string>(), null), Times.Once);
                baseRatePlanDao.VerifyAll();
                promotionManagerMock.Verify(pr => pr.UpsertPromotionRatePlanLinks(It.IsAny<RatePlan>()), Times.AtLeastOnce());
            }
Exemple #14
0
        /// <summary>
        /// Creates rates for a particular rate plan
        /// </summary>
        /// <param name="ratePlanRate">Rate plan</param>
        /// <param name="registerEvent">if true, will register event</param>
        /// <returns>Rate plan rate created</returns>
        public RatePlanRate CreateRatePlanRate(RatePlanRate ratePlanRate, bool registerEvent = true)
        {
            using (var tx = new BusinessTransaction())
            {
                ratePlanRateDao.Create(ratePlanRate);

                if (registerEvent)
                {
                    eventTrackingManager.CreateBusinessEventAsync(ratePlanRate.BusinessId,
                                                             BusinessEventTypesEnum.RatePlanRateAdded,
                                                             ratePlanRate.Id.ToString(CultureInfo.InvariantCulture));
                }

                tx.Commit();
            }
            return ratePlanRate;
        }
Exemple #15
0
 /// <summary>
 /// Validates if the MLOS for all rates is zero
 /// </summary>
 /// <param name="rate">Rates</param>
 private static void CheckIfAllRatesHaveMLOSZero(RatePlanRate rate)
 {
     if (rate.MonMinStay == default(int) && rate.TueMinStay == default(int) && rate.WedMinStay == default(int) && rate.ThuMinStay == default(int) &&
         rate.FriMinStay == default(int) && rate.SatMinStay == default(int) && rate.SunMinStay == default(int))
     {
         throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30090, "RoomTypeManager.CheckIfAllRatesHaveMLOSZero", arguments: new object[] { rate }));
     }
 }
Exemple #16
0
        /// <summary>
        /// Modifies rates for a particular rate plan
        /// </summary>
        /// <param name="ratePlanRate">Rate plan rate</param>
        /// <param name="registerEvent">if true, does event as well</param>
        /// <returns>Modified rate plan rate</returns>
        public virtual RatePlanRate ModifyRatePlanRates(RatePlanRate ratePlanRate, bool registerEvent = true)
        {
            if (ratePlanRate == null)
            {
                return null;
            }

            if (ratePlanRate.Id == default(int) || ratePlanRate.RatePlanId == default(int))
            {
                // can't modify with bad id
                throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30098, "RoomTypeManager.ModifyRatePlanRate", arguments: new object[] { ratePlanRate }));
            }

            if (ratePlanRate.IsValid())
            {
                using (var tx = new BusinessTransaction())
                {
                    ratePlanRateDao.Modify(ratePlanRate);

                    tx.Commit();
                }

                if (registerEvent)
                {
                    eventTrackingManager.CreateBusinessEventAsync(ratePlanRate.BusinessId, BusinessEventTypesEnum.RatePlanRateModified, ratePlanRate.Id.ToString(CultureInfo.InvariantCulture));
                }
            }

            return ratePlanRate;
        }
Exemple #17
0
        /// <summary>
        /// Set rates on variant rate plan
        /// </summary>
        /// <param name="varRate">RatePlanRate</param>
        /// <param name="variantRatePlan">VariantRatePlan</param>
        private void SetVariantRates(RatePlanRate varRate, VariantRatePlan variantRatePlan)
        {
            var variantType = variantRatePlan.VariantType.Type;
            var variantAmount = variantRatePlan.VariantAmount;

            varRate.MonRate = CalculateVariantRate(variantType, varRate.MonRate.HasValue ? varRate.MonRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[0]);
            varRate.MonMinStay = variantRatePlan.MinStay.HasValue && varRate.MonRate.HasValue ? variantRatePlan.MinStay.Value : default(int);

            varRate.TueRate = CalculateVariantRate(variantType, varRate.TueRate.HasValue ? varRate.TueRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[1]);
            varRate.TueMinStay = variantRatePlan.MinStay.HasValue && varRate.TueRate.HasValue ? variantRatePlan.MinStay.Value : default(int);

            varRate.WedRate = CalculateVariantRate(variantType, varRate.WedRate.HasValue ? varRate.WedRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[2]);
            varRate.WedMinStay = variantRatePlan.MinStay.HasValue && varRate.WedRate.HasValue ? variantRatePlan.MinStay.Value : default(int);

            varRate.ThuRate = CalculateVariantRate(variantType, varRate.ThuRate.HasValue ? varRate.ThuRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[3]);
            varRate.ThuMinStay = variantRatePlan.MinStay.HasValue && varRate.ThuRate.HasValue ? variantRatePlan.MinStay.Value : default(int);

            varRate.FriRate = CalculateVariantRate(variantType, varRate.FriRate.HasValue ? varRate.FriRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[4]);
            varRate.FriMinStay = variantRatePlan.MinStay.HasValue && varRate.FriRate.HasValue ? variantRatePlan.MinStay.Value : default(int);

            varRate.SatRate = CalculateVariantRate(variantType, varRate.SatRate.HasValue ? varRate.SatRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[5]);
            varRate.SatMinStay = variantRatePlan.MinStay.HasValue && varRate.SatRate.HasValue ? variantRatePlan.MinStay.Value : default(int);

            varRate.SunRate = CalculateVariantRate(variantType, varRate.SunRate.HasValue ? varRate.SunRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[6]);
            varRate.SunMinStay = variantRatePlan.MinStay.HasValue && varRate.SunRate.HasValue ? variantRatePlan.MinStay.Value : default(int);

            variantRatePlan.Rates = varRate;
        }
Exemple #18
0
            public void CreateBaseRatePlanRatesMlosHasToBeZeroWhenPriceIsZeroFails()
            {
                // Arrange
                var ratePlanRateDao = MockRepository.GenerateMock<IBaseRatePlanRatesDao>();
                var ratePlanManager = new RatePlanManager { RatePlanRateDao = ratePlanRateDao };

                const int RATE_PLAN_ID = 1;
                var rates = new RatePlanRate
                                {
                                    RatePlanId = RATE_PLAN_ID,
                                    MonMinStay = 1,
                                    MonRate = new decimal(10),
                                    TueMinStay= 1,
                                    TueRate = new decimal(10),
                                    WedMinStay = 1,
                                    WedRate = new decimal(10),
                                    ThuMinStay = 1,
                                    ThuRate = new decimal(10),
                                    FriMinStay = 1,
                                    FriRate = new decimal(10),
                                    SatMinStay = 1,
                                    SatRate = new decimal(10),
                                    SunMinStay = 2,
                                    SunRate = 0,
                               };

                var ratePlan = new BaseRatePlan { Rates = rates, RatePlanType = new RatePlanType { Type = RatePlanTypeEnum.Base } };

                // Act
                ratePlanManager.CreateBaseRatePlan(ratePlan);
            }
Exemple #19
0
        /// <summary>
        /// Set rates on variant rate plan
        /// </summary>
        /// <param name="varRate">RatePlanRate</param>
        /// <param name="variantRatePlan">VariantRatePlan</param>
        private void SetOccupantVariantRates(RatePlanRate varRate, VariantRatePlan variantRatePlan)
        {
            var variantType = variantRatePlan.VariantType.Type;
            var variantAmount = variantRatePlan.VariantAmount;

            varRate.MonRate = CalculateVariantRate(variantType, varRate.MonRate.HasValue ? varRate.MonRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[0], true);
            varRate.TueRate = CalculateVariantRate(variantType, varRate.TueRate.HasValue ? varRate.TueRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[1], true);
            varRate.WedRate = CalculateVariantRate(variantType, varRate.WedRate.HasValue ? varRate.WedRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[2], true);
            varRate.ThuRate = CalculateVariantRate(variantType, varRate.ThuRate.HasValue ? varRate.ThuRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[3], true);
            varRate.FriRate = CalculateVariantRate(variantType, varRate.FriRate.HasValue ? varRate.FriRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[4], true);
            varRate.SatRate = CalculateVariantRate(variantType, varRate.SatRate.HasValue ? varRate.SatRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[5], true);
            varRate.SunRate = CalculateVariantRate(variantType, varRate.SunRate.HasValue ? varRate.SunRate.Value : 0, variantAmount, variantRatePlan.ApplicableDays[6], true);
            variantRatePlan.Rates = varRate;
        }
Exemple #20
0
            public void ModifyRatePlanRateNoRatePlanIdThrowsException()
            {
                // Arrange
                var businessEventDao = MockRepository.GenerateMock<IBusinessEventDao>();
                var ratePlanRateDao = MockRepository.GenerateStrictMock<IBaseRatePlanRatesDao>();
                RatePlanManager ratePlanManager = new RatePlanManager
                {
                    BusinessEventDao = businessEventDao,
                    RatePlanRateDao = ratePlanRateDao
                };

                const long BUSINESS_ID = 1;
                const int RATE_PLAN_RATE_ID = 5;

                var ratePlanRate = new RatePlanRate { BusinessId = BUSINESS_ID, Id = RATE_PLAN_RATE_ID };

                ratePlanRateDao.Expect(rp => rp.Modify(Arg<RatePlanRate>.Is.Anything)).Repeat.Never();

                businessEventDao.Expect(be => be.Create(Arg<BusinessEvent>.Is.Anything)).Repeat.Never();

                try
                {
                    // Act
                    ratePlanManager.ModifyRatePlanRates(ratePlanRate);

                    // Assert
                    Assert.Fail("Validation exception was not thrown");
                }
                catch (ValidationException vex)
                {
                    Assert.AreEqual(Errors.SRVEX30098.ToString(), vex.Code, "Incorrect validation exception was thrown");
                    ratePlanRateDao.VerifyAllExpectations();
                    businessEventDao.VerifyAllExpectations();
                }
            }
            public void CreatRatePlanRateIsSuccessful()
            {
                using (new TestDataHelper(GetTestQuery(TestQuery.PopulateRatePlansWithoutRates), GetTestQuery(TestQuery.DeleteRatePlansWithoutRates)))
                {
                    // Arrange
                    var ratePlan = baseRatePlanDao.GetAll().FirstOrDefault();

                    Assert.IsTrue(ratePlan != null, "The test cannot be done because the ratePlan is null");

                    var ratePlanRate = new RatePlanRate
                    {
                        RatePlanId = ratePlan.Id,
                        MonRate = 100,
                        MonMinStay = 1,
                        TueRate = 100,
                        TueMinStay = 1,
                        WedRate = 100,
                        WedMinStay = 1,
                        ThuRate = 100,
                        ThuMinStay = 1,
                        FriRate = 150,
                        FriMinStay = 2,
                        SatRate = 150,
                        SatMinStay = 1,
                        SunRate = 100,
                        SunMinStay = 1
                    };

                    // Act
                    baseRatePlanRateDao.Create(ratePlanRate);

                    // Assert
                    // Check if the rate plan id is attributed
                    Assert.IsNotNull(ratePlanRate.Id, "The rate plan id was not attributed.");
                }
            }