From 251a56b2c2fe2bec9a1206b83b0456a0e742254c Mon Sep 17 00:00:00 2001 From: msalemcode Date: Thu, 23 Jan 2025 13:18:46 -0800 Subject: [PATCH] Get plan with AMP Offer ID and AMP Plan ID --- global.json | 2 +- .../Controllers/SchedulerController.cs | 28 +++++++++++++++++-- src/Services/Services/PlanService.cs | 22 +++++++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/global.json b/global.json index 9e5db15b..69aa839c 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "8.0.303", + "version": "8.0.405", "rollForward": "latestFeature" } } diff --git a/src/AdminSite/Controllers/SchedulerController.cs b/src/AdminSite/Controllers/SchedulerController.cs index 148860f0..6f237fb4 100644 --- a/src/AdminSite/Controllers/SchedulerController.cs +++ b/src/AdminSite/Controllers/SchedulerController.cs @@ -5,6 +5,7 @@ using System.Web; using Marketplace.SaaS.Accelerator.DataAccess.Contracts; using Marketplace.SaaS.Accelerator.DataAccess.Entities; +using Marketplace.SaaS.Accelerator.DataAccess.Services; using Marketplace.SaaS.Accelerator.Services.Models; using Marketplace.SaaS.Accelerator.Services.Services; using Marketplace.SaaS.Accelerator.Services.Utilities; @@ -41,11 +42,23 @@ public class SchedulerController : BaseController /// private SubscriptionService subscriptionService; + private PlanService plansService; + /// /// the plan service /// private IPlansRepository plansRepository; + /// + /// the offer repository + /// + private readonly IOffersRepository offerRepository; + + /// + /// the offer attribute repository + /// + private readonly IOfferAttributesRepository offerAttributeRepository; + /// /// the user repository /// @@ -71,7 +84,11 @@ public SchedulerController( IUsersRepository usersRepository, SaaSClientLogger logger, IAppVersionService appVersionService, - ISubscriptionUsageLogsRepository subscriptionUsageLogsRepository,IApplicationConfigRepository applicationConfigRepository):base(applicationConfigRepository, appVersionService) + ISubscriptionUsageLogsRepository subscriptionUsageLogsRepository, + IApplicationConfigRepository applicationConfigRepository, + IOfferAttributesRepository offerAttributeRepository, + IOffersRepository offerRepository + ) :base(applicationConfigRepository, appVersionService) { this.usersRepository = usersRepository; @@ -80,6 +97,10 @@ public SchedulerController( this.schedulerService = new MeteredPlanSchedulerManagementService(frequencyRepository, schedulerRepository, schedulerViewRepository,subscriptionUsageLogsRepository,applicationConfigRepository); this.subscriptionService = new SubscriptionService(subscriptionRepository,plansRepository); this.plansRepository = plansRepository; + this.offerAttributeRepository = offerAttributeRepository; + this.offerRepository = offerRepository; + this.plansService = new PlanService(this.plansRepository, this.offerAttributeRepository, this.offerRepository); + } /// @@ -240,8 +261,9 @@ public IActionResult AddNewScheduledTrigger(SchedulerUsageViewModel schedulerUsa return this.View("Error", "Subscription detail not found."); } // Retrieve the active Plan detail by AMP Plan ID - var selectedPlan = this.plansRepository.GetById(subscriptionDetail.AmpplanId); - // Check if subscriptionDetail is null + + var selectedPlan = this.plansService.GetPlansModelByAmpPlanIdOfferId(subscriptionDetail.AmpplanId, subscriptionDetail.AmpOfferId); + // Check if Plan is null if (selectedPlan == null) { this.logger.LogError("Plan detail not found for the given subscription."); diff --git a/src/Services/Services/PlanService.cs b/src/Services/Services/PlanService.cs index e0250433..d9697240 100644 --- a/src/Services/Services/PlanService.cs +++ b/src/Services/Services/PlanService.cs @@ -227,4 +227,26 @@ public List GetMeteredPlans() } + + /// + /// + /// + + public PlansModel GetPlansModelByAmpPlanIdOfferId(string ampPlanId,string ampOfferId) + { + var offer=this.offerRepository.GetAll().Where(o => o.OfferId == ampOfferId).FirstOrDefault(); + var plan = this.plansRepository.Get().Where(p => p.PlanId==ampPlanId && p.OfferId == offer.OfferGuid).FirstOrDefault(); + return new PlansModel + { + PlanId = plan.PlanId, + DisplayName = plan.DisplayName, + Description = plan.Description, + IsmeteringSupported = plan.IsmeteringSupported, + OfferID = plan.OfferId, + PlanGUID = plan.PlanGuid, + OfferName = offer.OfferName, + Id = plan.Id + }; + + } } \ No newline at end of file