Skip to content

Commit

Permalink
Get plan with AMP Offer ID and AMP Plan ID
Browse files Browse the repository at this point in the history
  • Loading branch information
msalemcode committed Jan 23, 2025
1 parent 2d64451 commit 251a56b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.303",
"version": "8.0.405",
"rollForward": "latestFeature"
}
}
28 changes: 25 additions & 3 deletions src/AdminSite/Controllers/SchedulerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,11 +42,23 @@ public class SchedulerController : BaseController
/// </summary>
private SubscriptionService subscriptionService;

private PlanService plansService;

/// <summary>
/// the plan service
/// </summary>
private IPlansRepository plansRepository;

/// <summary>
/// the offer repository
/// </summary>
private readonly IOffersRepository offerRepository;

/// <summary>
/// the offer attribute repository
/// </summary>
private readonly IOfferAttributesRepository offerAttributeRepository;

/// <summary>
/// the user repository
/// </summary>
Expand All @@ -71,7 +84,11 @@ public SchedulerController(
IUsersRepository usersRepository,
SaaSClientLogger<SchedulerController> logger,
IAppVersionService appVersionService,
ISubscriptionUsageLogsRepository subscriptionUsageLogsRepository,IApplicationConfigRepository applicationConfigRepository):base(applicationConfigRepository, appVersionService)
ISubscriptionUsageLogsRepository subscriptionUsageLogsRepository,
IApplicationConfigRepository applicationConfigRepository,
IOfferAttributesRepository offerAttributeRepository,
IOffersRepository offerRepository
) :base(applicationConfigRepository, appVersionService)

{
this.usersRepository = usersRepository;
Expand All @@ -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);

}

/// <summary>
Expand Down Expand Up @@ -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.");
Expand Down
22 changes: 22 additions & 0 deletions src/Services/Services/PlanService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,26 @@ public List<PlansModel> GetMeteredPlans()


}

/// <summary>
/// <param name="ampOfferId"></param>
/// <paramref name="ampPlanId"></paramre>

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
};

}
}

0 comments on commit 251a56b

Please sign in to comment.