/// <summary> /// Modify a pre-existing promotion /// </summary> /// <param name="promotion">Promotion</param> /// <returns>Success / Failure</returns> public bool ModifyPromotion(Promotion promotion) { bool status; // make sure the modified promotion data is valid promotion.IsValid(); //We need the promotions before doing modifications so we create push events for them as well var previousAssociatedRatePlanIds = promotionDao.GetRatePlanIdsByPromoId(promotion.Id); using (var tx = new BusinessTransaction()) { status = promotionDao.ModifyPromotion(promotion); ModifyPromotionRatePlanLinks(promotion); ModifyPromotionBlackoutDates(promotion); // commit the transaction tx.Commit(); } // write business event to event table after the commit and refresh promotion cache if (status) { eventTrackingManager.CreateBusinessEventAsync(promotion.BusinessId, BusinessEventTypesEnum.PromotionModified, promotion.Id); //create the events for the rateplans attached to the promotion //we don't pass dates in this case as we want it to do a full update for these rateplans previousAssociatedRatePlanIds.AddRange(promotion.AssociatedRatePlanIds); previousAssociatedRatePlanIds.Distinct().ToList().ForEach(ratePlan => RatePlanManager.CreateRatePlanUpdateEvent(ratePlan, promotion.BusinessId)); // refresh cache for this promotion business Cache.Cache.PromoCache.Invalidate(promotion.BusinessId); } return status; }
/// <summary> /// Create a new promotion /// </summary> /// <param name="promotion">Promotion to create</param> public void CreatePromotion(Promotion promotion) { if (promotion.Status == null) { promotion.Status = new PromotionStatus { Type = PromotionStatusEnum.Active }; } if (promotion.IsValid()) { using (var tx = new BusinessTransaction()) { promotionDao.CreatePromotion(promotion); // Create promo rate plan links var links = promotion.AssociatedRatePlanIds.Select(ratePlanId => new PromotionRatePlanLink { PromotionId = promotion.Id, RatePlanId = ratePlanId }).ToList(); promotionDao.CreateRatePlanLinks(links); // Create promo blackout dates CreatePromotionBlackoutDates(promotion); tx.Commit(); } if (promotion.Id != default(int)) { eventTrackingManager.CreateBusinessEventAsync(promotion.BusinessId, BusinessEventTypesEnum.PromotionAdded, promotion.Id); //create the events for the rateplans attached to the promotion promotion.AssociatedRatePlanIds.ForEach(ratePlan => RatePlanManager.CreateRatePlanUpdateEvent(ratePlan, promotion.BusinessId, promotion.StayStartDate, promotion.StayEndDate)); // refresh cache for this promotion business Cache.Cache.PromoCache.Invalidate(promotion.BusinessId); } } }