/// <summary> /// This method will handle updates for a rate plan /// </summary> /// <param name="rateChangeMessage">RatePlan change message</param> public void Handle(RatePlanChangeMessage rateChangeMessage) { long businessId = rateChangeMessage.ProviderId.ToLong(); var ratePlanId = Helper.GetRatePlanIdFromProductGuid(rateChangeMessage.ProductTypeId); var roomTypeId = Helper.GetRoomTypeIdFromProductGuid(rateChangeMessage.ProductTypeId); var startDate = rateChangeMessage.StartDate; var endDate = rateChangeMessage.EndDate; var dateMessage = string.Empty; if (endDate != null && startDate != null) { dateMessage = string.Format(" for dates {0} - {1}", startDate, endDate); } Logger.LogInfo("Message received room Business Id: {0}, room type Id: {1}, rate plan id: {2}{3}", null, businessId, roomTypeId, ratePlanId, dateMessage); var provider = businessManager.GetBusinessInformationForIntegration(businessId); switch (rateChangeMessage.ChangeType) { //for an insert of a new rate plan we need to generate a new room type message with the associated room type / rate plan information case ChangeType.Insert: case ChangeType.Update: { rateAmountUpdate.SendRateAmountUpdate(provider.ShortName, businessId, roomTypeId, ratePlanId, startDate, endDate); rateRestrictionUpdate.SendRatesRestrictionUpdate(provider.ShortName, roomTypeId, ratePlanId, startDate: startDate, endDate: endDate); break; } case ChangeType.Delete: { rateRestrictionUpdate.SendRatesRestrictionClose(provider.ShortName, roomTypeId, ratePlanId, startDate, endDate); break; } } }
/// <summary> /// Process Rate Plan Changes /// </summary> /// <param name="queueItem">Queue Item</param> /// <param name="providerSubscriberOptInLookup">Provider Subscriber Opt In list</param> public bool ProcessChange(IQueueItem queueItem, ref ProviderSubscriberOptInsLookup providerSubscriberOptInLookup) { var ratePlanChange = XmlSerialization.XmlDeserializeFromString<PushRatePlanUpdate>(queueItem.Payload); ChangeType changeType; RatePlanChangeType ratePlanChangeType; Enum.TryParse(ratePlanChange.Action, out ratePlanChangeType); switch (ratePlanChangeType) { //adding of a new rate plan will create a new roomtype in the Handle - this is because every RoomType/RatePlan combination is treated as a Product Type in Expedia case RatePlanChangeType.AddRatePlan: changeType = ChangeType.Insert; break; case RatePlanChangeType.ModifyRatePlan: changeType = ChangeType.Update; break; case RatePlanChangeType.DeleteRatePlan: changeType = ChangeType.Delete; break; default: return false; } var ratePlanChangeMessage = new RatePlanChangeMessage(ratePlanChange.BusinessId.ToGuid(), changeType, Helper.GetProductGuid(ratePlanChange.RoomTypeId, ratePlanChange.RatePlanId), ratePlanChange.StartDate, ratePlanChange.EndDate); bool isSuccess = true; foreach (var messagingIntegratorService in CreateServices(ratePlanChangeMessage)) { isSuccess &= messagingIntegratorService.ProcessAndQueueChangeUpdates(providerSubscriberOptInLookup, ratePlanChangeMessage); } return isSuccess; }
/// <summary> /// This method will handle updates for a rate plan /// </summary> /// <param name="subscriberByOptinList">List of providers opted into AIG</param> /// <param name="rateChangeMessage">RatePlan change message</param> /// <returns>True is successful otherwise False</returns> private bool HandleRatePlanUpdate(SubscriberByOptinList subscriberByOptinList, RatePlanChangeMessage rateChangeMessage) { switch (rateChangeMessage.ChangeType) { //for an insert of a new rate plan we need to generate a new room type message with the associated room type / rate plan information case ChangeType.Insert: { var provider = businessManager.GetBusinessInformationForIntegration(rateChangeMessage.ProviderId.ToLong()); var roomTypeRatePlan = roomTypeManager.GetByRoomTypeIdAndRatePlanId(Helper.GetRoomTypeIdFromProductGuid(rateChangeMessage.ProductTypeId), Helper.GetRatePlanIdFromProductGuid(rateChangeMessage.ProductTypeId)); //only handle base rate plans for now if (roomTypeRatePlan.RatePlanTypeCode != RatePlanTypeEnum.Base.GetCode()) { return true; } var interfaceProduct = ConvertRoomTypeToAigProduct(roomTypeRatePlan, provider.CheckinTime, provider.CheckoutTime); interfaceProduct.RatesRestrictionsDateRange = ExtractRateRestrictions(provider.Id, rateChangeMessage.ProductTypeId); CheckPriceRatesExists(interfaceProduct, rateChangeMessage.ProviderId); //create message for each subscriber if (subscriberByOptinList.GetSubscribers().Any(subscriberId => !QueueMessage(CreateProductAddRemoveMessage(interfaceProduct, subscriberId, rateChangeMessage.ProviderId)))) { return false; } break; } case ChangeType.Update: case ChangeType.Delete: { var rateRestrictions = ExtractRateRestrictions(rateChangeMessage.ProviderId.ToLong(), rateChangeMessage.ProductTypeId); if (rateRestrictions == null) { Logger.Info(String.Format("RoomType setup incomplete: No rate restrictions found for business {0} with room type {1}", rateChangeMessage.ProviderId, rateChangeMessage.ProductTypeId)); } else { foreach (var subscriberId in subscriberByOptinList.GetSubscribers()) { if (rateRestrictions.EndDate > DateTime.Now.Date) { var rateRestrictionChange = CreateProductRestrictionChangeMessage(subscriberId, rateChangeMessage.ProviderId, rateChangeMessage.ProductTypeId, rateRestrictions); if (!QueueMessage(rateRestrictionChange)) { return false; } } else { Logger.Info(string.Format("The daily rates with id {0} changed was for a prior time period", Helper.GetRatePlanIdFromProductGuid(rateChangeMessage.ProductTypeId))); } } } } break; } return true; }