Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Scheduler Entry Form To get PlanID from Plan Repo #791

Merged
merged 4 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 46 additions & 5 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,6 +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 @@ -66,14 +84,22 @@ 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;
this.logger = logger;
this.meteredRepository = meteredRepository;
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);

}

Expand Down Expand Up @@ -134,8 +160,6 @@ public IActionResult NewScheduler(string subscriptionId, string dimId, string qu
Value = item.Id.ToString(),
});
}
// Create Plan Dropdown list
List<SelectListItem> PlanList = new List<SelectListItem>();
List<SelectListItem> DimensionsList = new List<SelectListItem>();

schedulerUsageViewModel.DimensionsList = new SelectList(DimensionsList, "Value", "Text");
Expand Down Expand Up @@ -228,13 +252,30 @@ public IActionResult AddNewScheduledTrigger(SchedulerUsageViewModel schedulerUsa
{
try
{
var selectedDimension = this.meteredRepository.Get(int.Parse(schedulerUsageViewModel.SelectedDimension));
//Retrieve the active subscription detail to get the AMP Plan ID
var subscriptionDetail = this.subscriptionService.GetActiveSubscriptionsWithMeteredPlan().Where(s => s.Id == Convert.ToInt32(schedulerUsageViewModel.SelectedSubscription)).FirstOrDefault();
// Check if subscriptionDetail is null
if (subscriptionDetail == null)
{
this.logger.LogError("Subscription detail not found for the given subscription ID.");
return this.View("Error", "Subscription detail not found.");
}
// Retrieve the active Plan detail by AMP Plan ID

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.");
return this.View("Error", "Plan detail not found.");
}

MeteredPlanSchedulerManagementModel schedulerManagement = new MeteredPlanSchedulerManagementModel()
{
FrequencyId = Convert.ToInt32(schedulerUsageViewModel.SelectedSchedulerFrequency),
SchedulerName = Convert.ToString(schedulerUsageViewModel.SchedulerName),
SubscriptionId = Convert.ToInt32(schedulerUsageViewModel.SelectedSubscription),
PlanId = Convert.ToInt32(selectedDimension.PlanId),
PlanId = Convert.ToInt32(selectedPlan.Id),
DimensionId = Convert.ToInt32(schedulerUsageViewModel.SelectedDimension),
Quantity = Convert.ToDouble(schedulerUsageViewModel.Quantity),
StartDate = schedulerUsageViewModel.FirstRunDate.AddHours(schedulerUsageViewModel.TimezoneOffset)
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
};

}
}
Loading