예제 #1
0
        /// <summary>
        /// Create the occupant rate plan rate
        /// </summary>
        /// <param name="baseRatePlanOccupantRate">occupant rate plan rate</param>
        /// <param name="registerEvent">if true, registers the event</param>
        /// <returns>rate plan rate created</returns>
        private RatePlanRate CreateOccupantRatePlanRate(BaseRatePlanOccupantRate baseRatePlanOccupantRate, bool registerEvent = true)
        {
            using (var tx = new BusinessTransaction())
            {
                ratePlanRateDao.CreateBaseOccupantRates(baseRatePlanOccupantRate);

                tx.Commit();
            }

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

            return baseRatePlanOccupantRate;
        }
예제 #2
0
        /// <summary>
        /// Modifies rates for a particular occupant rate plan
        /// </summary>
        /// <param name="baseRatePlanOccupantRate">occupant Rate plan rate</param>
        /// <param name="registerEvent">if true, registers the event</param>
        /// <returns>Modified occupant rate plan rate</returns>
        private RatePlanRate ModifyRatePlanRates(BaseRatePlanOccupantRate baseRatePlanOccupantRate, bool registerEvent = true)
        {
            if (baseRatePlanOccupantRate == null)
            {
                return null;
            }

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

            if (baseRatePlanOccupantRate.IsValid())
            {
                using (var tx = new BusinessTransaction())
                {
                    ratePlanRateDao.ModifyBaseOccupantRatesByRatePlanId(baseRatePlanOccupantRate);

                    tx.Commit();
                }

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

            return baseRatePlanOccupantRate;
        }
예제 #3
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
            };

        }
예제 #4
0
        /// <summary>occupant base rate plan rates
        /// </summary>
        /// <param name="ratePlanRates">collection of RatePlanRate</param>
        /// <returns>collection of created/edited RatePlanRate</returns>
        private List<RatePlanRate> CreateEditOccupantBasePlanRates(List<RatePlanRate> ratePlanRates)
        {
            var ratesPlanRate = new List<RatePlanRate>();

            if (ratePlanRates == null)
            {
                throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30088, "RoomTypeManager.CreateEditBaseRatePlanRates"));
            }


            var rateGroups =
                from rate in ratePlanRates
                group rate by rate.PeriodId into ratePlanGroups
                orderby ratePlanGroups.Key
                select ratePlanGroups;

            List<BaseRatePlanOccupantRate> baseRatePlanOccupantRates = new List<BaseRatePlanOccupantRate>();
            foreach (var rateGroup in rateGroups)
            {
                BaseRatePlanOccupantRate baseRatePlanOccupantRate = new BaseRatePlanOccupantRate();

                // Get adult and child rates for each rate group
                foreach (var rate in rateGroup)
                {
                    baseRatePlanOccupantRate.RatePlanId = rate.RatePlanId;
                    baseRatePlanOccupantRate.PeriodId = rate.PeriodId;
                    baseRatePlanOccupantRate.BusinessId = rate.BusinessId;
                    baseRatePlanOccupantRate.Id = rate.Id;

                    if (rate.OccupancyRateType == OccupancyRateType.Adult)
                    {
                        baseRatePlanOccupantRate.MonAdultRate = rate.MonRate;
                        baseRatePlanOccupantRate.TueAdultRate = rate.TueRate;
                        baseRatePlanOccupantRate.WedAdultRate = rate.WedRate;
                        baseRatePlanOccupantRate.ThuAdultRate = rate.ThuRate;
                        baseRatePlanOccupantRate.FriAdultRate = rate.FriRate;
                        baseRatePlanOccupantRate.SatAdultRate = rate.SatRate;
                        baseRatePlanOccupantRate.SunAdultRate = rate.SunRate;
                    }
                    if (rate.OccupancyRateType == OccupancyRateType.Child)
                    {
                        baseRatePlanOccupantRate.MonChildRate = rate.MonRate;
                        baseRatePlanOccupantRate.TueChildRate = rate.TueRate;
                        baseRatePlanOccupantRate.WedChildRate = rate.WedRate;
                        baseRatePlanOccupantRate.ThuChildRate = rate.ThuRate;
                        baseRatePlanOccupantRate.FriChildRate = rate.FriRate;
                        baseRatePlanOccupantRate.SatChildRate = rate.SatRate;
                        baseRatePlanOccupantRate.SunChildRate = rate.SunRate;
                    }
                }
                baseRatePlanOccupantRates.Add(baseRatePlanOccupantRate);
            }
            
            var eventType = BusinessEventTypesEnum.RatePlanAdded;

            using (var trans = new BusinessTransaction())
            {
                foreach (var occupantRate in baseRatePlanOccupantRates)
                {
                    // create base rate plan rates for periods without base rate plan rates
                    if (occupantRate.PeriodId != null && occupantRate.Id == default(int))
                    {
                        var createdRatePlan = CreateOccupantRatePlanRate(occupantRate, false);
                        ratesPlanRate.Add(createdRatePlan);
                    }
                        //create evergreen base rate plan rates
                    else if (occupantRate.PeriodId == null && occupantRate.Id == default(int))
                    {
                        var createdRatePlan = CreateOccupantRatePlanRate(occupantRate, false);
                        ratesPlanRate.Add(createdRatePlan);
                    }

                        // modify existing base rate plan rates
                    else
                    {
                        eventType = BusinessEventTypesEnum.RatePlanModified;
                        var modifiedRatePlan = ModifyRatePlanRates(occupantRate, false);
                        ratesPlanRate.Add(modifiedRatePlan);
                    }
                }
                
                trans.Commit();
            }

            // if any db operations happened create event
            if (ratesPlanRate.Any())
            {
                eventTrackingManager.CreateBusinessEventAsync(baseRatePlanOccupantRates.First().BusinessId, eventType, baseRatePlanOccupantRates.First().RatePlanId.ToString());
            }

            return ratesPlanRate;
        }
예제 #5
0
        /// <summary>
        /// Modify Occupant RatePlanRate
        /// </summary>
        /// <param name="ratePlanRate">RatePlan rate to change</param>
        private void ModifyAdultChildBaseOccupantRatesByRatePlanId(BaseRatePlanOccupantRate ratePlanRate)
        {
            const string SQL_STATEMENT = @"
                UPDATE Pricing.BaseRatePlanOccupantRates
                set 
                        RatePlanId = @RatePlanId,
                        PeriodId = @PeriodId,
                        MonAdultRate = @MonAdultRate,
                        MonChildRate = @MonChildRate,
                        TueAdultRate = @TueAdultRate,
                        TueChildRate = @TueChildRate,
                        WedAdultRate = @WedAdultRate,
                        WedChildRate = @WedChildRate,
                        ThuAdultRate = @ThuAdultRate,
                        ThuChildRate = @ThuChildRate,
                        FriAdultRate = @FriAdultRate,
                        FriChildRate = @FriChildRate,
                        SatAdultRate = @SatAdultRate,
                        SatChildRate = @SatChildRate,
                        SunAdultRate = @SunAdultRate,
                        SunChildRate = @SunChildRate,
                        UpdatedByUserId = @UpdatedByUserId
                where
                        Id = @Id";

            var parameters = new List<SqlParameter>
            {
                DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.Id, ratePlanRate.Id),
                DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.RatePlanId, ratePlanRate.RatePlanId),
                DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.PeriodId, ratePlanRate.PeriodId),
                DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.MonAdultRate, ratePlanRate.MonAdultRate),
                DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.MonChildRate, ratePlanRate.MonChildRate),
                DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.TueAdultRate, ratePlanRate.TueAdultRate),
                DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.TueChildRate, ratePlanRate.TueChildRate),
                DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.WedAdultRate, ratePlanRate.WedAdultRate),
                DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.WedChildRate, ratePlanRate.WedChildRate),
                DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.ThuAdultRate, ratePlanRate.ThuAdultRate),
                DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.ThuChildRate, ratePlanRate.ThuChildRate),
                DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.FriAdultRate, ratePlanRate.FriAdultRate),
                DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.FriChildRate, ratePlanRate.FriChildRate),
                DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.SatAdultRate, ratePlanRate.SatAdultRate),
                DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.SatChildRate, ratePlanRate.SatChildRate),
                DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.SunAdultRate, ratePlanRate.SunAdultRate),
                DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.SunChildRate, ratePlanRate.SunChildRate)
            };

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

            DbHelper.ExecuteNonQueryCommand(SQL_STATEMENT, parameters: parameters);
        }
예제 #6
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;
        }
예제 #7
0
 private bool IsAdultChildBaseRatePlanOccupantRateUpdate(BaseRatePlanOccupantRate ratePlanRate)
 {
     return IsAdultBaseRatePlanOccupantRateUpdate(ratePlanRate) && IsChildBaseRatePlanOccupantRateUpdate(ratePlanRate);
 }
예제 #8
0
 private bool IsChildBaseRatePlanOccupantRateUpdate(BaseRatePlanOccupantRate ratePlanRate)
 {
     return ratePlanRate.MonChildRate != null &&
            ratePlanRate.TueChildRate != null &&
            ratePlanRate.WedChildRate != null &&
            ratePlanRate.ThuChildRate != null &&
            ratePlanRate.FriChildRate != null &&
            ratePlanRate.SatChildRate != null &&
            ratePlanRate.SunChildRate != null;
 }
예제 #9
0
 private bool IsAdultBaseRatePlanOccupantRateUpdate(BaseRatePlanOccupantRate ratePlanRate)
 {
     return ratePlanRate.MonAdultRate != null &&
            ratePlanRate.TueAdultRate != null &&
            ratePlanRate.WedAdultRate != null &&
            ratePlanRate.ThuAdultRate != null &&
            ratePlanRate.FriAdultRate != null &&
            ratePlanRate.SatAdultRate != null &&
            ratePlanRate.SunAdultRate != null;
 }
예제 #10
0
        /// <summary>
        /// Modify Occupant RatePlanRate
        /// </summary>
        /// <remarks>
        /// Move the logic to manager when time allows
        /// </remarks>
        /// <param name="ratePlanRate">RatePlan rate to change</param>
        public void ModifyBaseOccupantRatesByRatePlanId(BaseRatePlanOccupantRate ratePlanRate)
        {
            if (IsAdultChildBaseRatePlanOccupantRateUpdate(ratePlanRate))
            {
                ModifyAdultChildBaseOccupantRatesByRatePlanId(ratePlanRate);
                return;
            }

            if (IsChildBaseRatePlanOccupantRateUpdate(ratePlanRate))
            {
                ModifyChildBaseOccupantRatesByRatePlanId(ratePlanRate);
                return;
            }

            if (IsAdultBaseRatePlanOccupantRateUpdate(ratePlanRate))
            {
                ModifyAdultBaseOccupantRatesByRatePlanId(ratePlanRate);
            }
            
        }
예제 #11
0
         /// <summary>
        /// Create BaseRatePlan OccupantRate
        /// </summary>
        /// <param name="baseRatePlanOccupantRate">BaseRatePlanOccupantRate</param>
        public void CreateBaseOccupantRates(BaseRatePlanOccupantRate baseRatePlanOccupantRate)
        {
            const string SQL_STATEMENT = @"
                INSERT INTO Pricing.BaseRatePlanOccupantRates
                (
                        RatePlanId,
                        PeriodId,
                        MonAdultRate,
                        MonChildRate,
                        TueAdultRate,
                        TueChildRate,
                        WedAdultRate,
                        WedChildRate,
                        ThuAdultRate,
                        ThuChildRate,
                        FriAdultRate,
                        FriChildRate,
                        SatAdultRate,
                        SatChildRate,
                        SunAdultRate,
                        SunChildRate,
                        UpdatedByUserId
                )
                VALUES
                (
                        @RatePlanId,
                        @PeriodId,
                        @MonAdultRate,
                        @MonChildRate,
                        @TueAdultRate,
                        @TueChildRate,
                        @WedAdultRate,
                        @WedchildRate,
                        @ThuAdultRate,
                        @ThuChildRate,
                        @FriAdultRate,
                        @FriChildRate,
                        @SatAdultRate,
                        @SatChildRate,
                        @SunAdultRate,
                        @SunChildRate,
                        @UpdatedByUserId
                )
                SELECT @Id = SCOPE_IDENTITY()";

            var parameters = new List<SqlParameter>
                                 {
                                     DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.RatePlanId,
                                                              baseRatePlanOccupantRate.RatePlanId),
                                     DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.PeriodId,
                                                              baseRatePlanOccupantRate.PeriodId),
                                     DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.MonAdultRate,
                                                              baseRatePlanOccupantRate.MonAdultRate),
                                     DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.MonChildRate,
                                                              baseRatePlanOccupantRate.MonChildRate),
                                     DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.TueAdultRate,
                                                              baseRatePlanOccupantRate.TueAdultRate),
                                     DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.TueChildRate,
                                                              baseRatePlanOccupantRate.TueChildRate),
                                     DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.WedAdultRate,
                                                              baseRatePlanOccupantRate.WedAdultRate),
                                     DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.WedChildRate,
                                                              baseRatePlanOccupantRate.WedChildRate),
                                     DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.ThuAdultRate,
                                                              baseRatePlanOccupantRate.ThuAdultRate),
                                     DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.ThuChildRate,
                                                              baseRatePlanOccupantRate.ThuChildRate),
                                     DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.FriAdultRate,
                                                              baseRatePlanOccupantRate.FriAdultRate),
                                     DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.FriChildRate,
                                                              baseRatePlanOccupantRate.FriChildRate),
                                     DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.SatAdultRate,
                                                              baseRatePlanOccupantRate.SatAdultRate),
                                     DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.SatChildRate,
                                                              baseRatePlanOccupantRate.SatChildRate),
                                     DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.SunAdultRate,
                                                              baseRatePlanOccupantRate.SunAdultRate),
                                     DbHelper.CreateParameter(BaseRatePlanOccupantRateMapper.Parameters.SunChildRate,
                                                              baseRatePlanOccupantRate.SunChildRate)
                                 };

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

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

            DbHelper.ExecuteNonQueryCommand(SQL_STATEMENT, parameters: parameters);
            baseRatePlanOccupantRate.Id = DbHelper.ParameterValue<int>(outputKey);
        }