diff --git a/src/AdminSite/Controllers/SchedulerController.cs b/src/AdminSite/Controllers/SchedulerController.cs index 3137468f..148860f0 100644 --- a/src/AdminSite/Controllers/SchedulerController.cs +++ b/src/AdminSite/Controllers/SchedulerController.cs @@ -231,11 +231,22 @@ public IActionResult AddNewScheduledTrigger(SchedulerUsageViewModel schedulerUsa { try { - //Get AMP Plan ID from Subscription Detail + //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(); - // Get Plan detail by AMP Plan ID + // 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.plansRepository.GetById(subscriptionDetail.AmpplanId); - + // Check if subscriptionDetail 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() {