/// <summary> /// Map the basic fields for the BaseRatePlan table to the BaseRatePlan model object /// </summary> /// <param name="record">The SqlDataReader with the executed query result</param> /// <param name="ratePlan">The rate plan to map to</param> /// <param name="prefix">a prefix used to identify fields for the BaseRatePlan model in the resultset if required</param> /// <returns>An instance of Model.Pricing.BaseRatePlan</returns> internal static void MapRecord(IDataRecord record, RatePlan ratePlan, string prefix = "") { ratePlan.Id = DbHelper.ConvertValue<int>(record[prefix + Parameters.Id]); ratePlan.RoomTypeId = DbHelper.ConvertValueNull<int>(record[prefix + Parameters.RoomTypeId]); ratePlan.RatePlanType = new RatePlanType { Type = DbHelper.ConvertEnumValue<RatePlanTypeEnum>(record[Parameters.RatePlanTypeCode.ToString()]), Name = DbHelper.ConvertValue<string>(record[Parameters.RatePlanTypeName.ToString()]) }; ratePlan.CurrencyCode = DbHelper.ConvertValue<string>(record[prefix + Parameters.CurrencyCode]); ratePlan.BoardBasis = EnumEntityMapper.MapRecord(record, Parameters.BoardBasis.ToString()); ratePlan.CancellationClass = EnumEntityMapper.MapRecord(record, Parameters.CancellationClass.ToString()); ratePlan.MaxOccupancy = DbHelper.ConvertValue<int?>(record[prefix + Parameters.MaxOccupancy]); ratePlan.MaxAdults = DbHelper.ConvertValue<int?>(record[prefix + Parameters.MaxAdults]); ratePlan.MaxChildren = DbHelper.ConvertValue<int?>(record[prefix + Parameters.MaxChildren]); ratePlan.DisplayName = DbHelper.ConvertValue<string>(record[prefix + Parameters.DisplayName]); if (ratePlan.RatePlanType.Type == RatePlanTypeEnum.Base) { ratePlan.UseOccupancyRates = DbHelper.ConvertValue<bool>(record[prefix + Parameters.UseOccupancyRates]); } }
/// <summary> /// Create a Rate Plan /// </summary> /// <param name="ratePlan">Rate Plan to create</param> public void Create(RatePlan ratePlan) { const string SQL_STATEMENT = @" INSERT INTO Pricing.RatePlan ( BusinessId, RatePlanTypeCode, UpdatedByUserId ) VALUES ( @BusinessId, @RatePlanTypeCode, @UpdatedByUserId ) SELECT @Id = SCOPE_IDENTITY()"; var parameters = new List<SqlParameter> { DbHelper.CreateParameter(RatePlanMapper.Parameters.BusinessId, ratePlan.BusinessId), DbHelper.CreateParameter(RatePlanMapper.Parameters.RatePlanTypeCode, ratePlan.RatePlanType.Type.GetCode()) }; // Add auditing parameters AuditFieldsHelper.PopulateAuditFields(parameters); SqlParameter outputKey; parameters.Add(outputKey = DbHelper.CreateParameterOut<int>(RatePlanMapper.Parameters.Id, SqlDbType.Int)); DbHelper.ExecuteNonQueryCommand(SQL_STATEMENT, parameters: parameters); ratePlan.Id = DbHelper.ParameterValue<int>(outputKey); }
/// <summary> /// Set the default period when the period is not set /// </summary> /// <param name="ratePlan">Rate Plan</param> /// <param name="cultureCode">Culture Code</param> private void SetDefaultPeriod(RatePlan ratePlan, string cultureCode) { if (ratePlan.Period == null) { ratePlan.Period = new Period { Id = 0, Name = dictionaryDao.GetItemByKey(EVERGREEN_PERIOD_NAME, cultureCode) }; } }
/// <summary> /// Set the default rates for evergreen period /// </summary> /// <param name="baseRatePlan">RatePlan</param> private static void SetDefaultPeriodBaseRates(RatePlan baseRatePlan) { baseRatePlan.Rates = new RatePlanRate { MonRate = null, MonMinStay = MIN_STAY, TueRate = null, TueMinStay = MIN_STAY, WedRate = null, WedMinStay = MIN_STAY, ThuRate = null, ThuMinStay = MIN_STAY, FriRate = null, FriMinStay = MIN_STAY, SatRate = null, SatMinStay = MIN_STAY, SunRate = null, SunMinStay = MIN_STAY, RatePlanId = baseRatePlan.Id }; }
/// <summary> /// Create a variant rate from the base rate /// </summary> /// <param name="baseRatePlan">Base rate plan</param> /// <param name="defaultName">Name for the rate</param> /// <returns>Return variant rate</returns> private static VariantRatePlan CreateVariantFromBase(RatePlan baseRatePlan, string defaultName) { return new VariantRatePlan { Id = baseRatePlan.Id, RoomTypeId = baseRatePlan.RoomTypeId, RatePlanType = baseRatePlan.RatePlanType, MaxOccupancy = baseRatePlan.MaxOccupancy, MaxAdults = baseRatePlan.MaxAdults, MaxChildren = baseRatePlan.MaxChildren, BoardBasis = baseRatePlan.BoardBasis, CancellationClass = baseRatePlan.CancellationClass, RoomType = baseRatePlan.RoomType, CurrencyCode = baseRatePlan.CurrencyCode, BusinessId = baseRatePlan.BusinessId, ApplicableDays = Constants.FULL_AVAILABILITY, Rates = baseRatePlan.Rates, DisplayName = baseRatePlan.DisplayName, Name = defaultName, IsActive = true }; }
/// <summary> /// Uses test schema to create a rate plan /// </summary> /// <param name="businessId">business to add rate plan to</param> /// <param name="roomType">room type for rate plan</param> /// <param name="ratePlan">base rateplan object to use for other params</param> /// <returns>id of created rateplan, or 0 if not successful</returns> public static int CreateRatePlan(long businessId, string roomType, RatePlan ratePlan) { //if (ratePlan == null) //{ return 0; //} //var parameters = new List<SqlParameter> //{ // DbHelper.CreateParameter(BUSINESS_ID, businessId), // DbHelper.CreateParameter(ROOMTYPE, roomType), // DbHelper.CreateParameter(NAME, ratePlan.Name), // DbHelper.CreateParameter(MAX_OCCUPANCY, ratePlan.MaxOccupancy.HasValue ? ratePlan.MaxOccupancy.Value : 1), // DbHelper.CreateParameter(MINADULT, ratePlan.MinAdult.HasValue ? ratePlan.MinAdult.Value : 1), // DbHelper.CreateParameter(MAXADULT, ratePlan.MaxAdult.HasValue ? ratePlan.MaxAdult.Value : 1), // DbHelper.CreateParameter(MAXCHILD, ratePlan.MaxChild.HasValue ? ratePlan.MaxChild.Value : 0), // DbHelper.CreateParameter(MIN_STAY, ratePlan.MinStay.HasValue ? ratePlan.MinStay.Value : 1), // DbHelper.CreateParameter(RATEADJUSTMENTTYPE, ratePlan.RateAdjustmentType.Type.GetCode()), // DbHelper.CreateParameter(RATEADJUSTMENTAMOUNT, ratePlan.RateAdjustmentAmount ?? 0), // DbHelper.CreateParameter(ISADULTONLY, ratePlan.IsAdultOnly), // DbHelper.CreateParameter(ISAVAILABLEATALLTIMES, ratePlan.IsAvailableAtAllTimes), // DbHelper.CreateParameter(ISBREAKFASTINCLUDED, ratePlan.IsBreakfastIncluded), // DbHelper.CreateParameter(ISNONREFUNDABLE, ratePlan.IsNonRefundable), // DbHelper.CreateParameter(ISMEALBASIS, ratePlan.IsMealBasis) //}; //SqlParameter outputKey = DbHelper.CreateParameterOut<int>(RATEPLAN_ID, SqlDbType.Int); //parameters.Add(outputKey); //DbHelper.ExecuteNonQueryCommand(CREATE_RATEPLAN, CommandType.StoredProcedure, parameters); //return DbHelper.ParameterValue<int>(outputKey); }
///<summary> /// Converts RatePlan to RatePlanDto ///</summary> ///<param name="ratePlan">RatePlan to convert</param> ///<returns>Rate plan DTO</returns> private static RatePlanDto ConvertRatePlanToDto(RatePlan ratePlan) { if (ratePlan == null) { return null; } var ratePlanResult = new RatePlanDto { Id = ratePlan.Id.HasValue ? ratePlan.Id.Value : 0, Name = ratePlan.Name, RoomTypeId = ratePlan.RoomTypeId, IsBaseRatePlan = ratePlan.IsBaseRatePlan, IsNonRefundable = ratePlan.IsNonRefundable, MaxSleep = ratePlan.MaxSleep, MaxAdult = ratePlan.MaxAdult, MinAdult = ratePlan.MinAdult, MaxChild = ratePlan.MaxChild, WeeklyAvailability = ConvertWeeklyAvailabilityToDto(ratePlan.WeeklyAvailability) }; // Set the weekly availability if it is there return ratePlanResult; }
/// <summary> /// creates / deletes all links needed in given rateplan /// </summary> /// <remarks> /// null rateplan or null associated promotions returns doing nothing /// </remarks> /// <param name="rateplan">rateplan to update promo links for</param> public void UpsertPromotionRatePlanLinks(RatePlan rateplan) { if (rateplan == null || rateplan.AssociatedPromotions == null) { return; } var existingPromos = Cache.Cache.PromoCache.TryGetValue(rateplan.BusinessId); var existingPromoIds = existingPromos.Where(promo => promo.AssociatedRatePlanIds.Any(rp => rp == rateplan.Id)) .Select(pr => pr.Id); var promoLinksToDelete = existingPromoIds.Where(x => rateplan.AssociatedPromotions.All(pr => pr.Id != x)); promotionDao.DeletePromoLinks(rateplan.Id, promoLinksToDelete); var linksToCreate = rateplan.AssociatedPromotions .Where(x => existingPromoIds.All(y => y != x.Id)) .Select(promo => new PromotionRatePlanLink { PromotionId = promo.Id, RatePlanId = rateplan.Id }).ToList(); promotionDao.CreateRatePlanLinks(linksToCreate); //Make sure cache stays up to date Cache.Cache.PromoCache.Invalidate(rateplan.BusinessId); }