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

Msalem/fix scheduler button #570

Closed
wants to merge 13 commits into from
7 changes: 7 additions & 0 deletions src/AdminSite/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,13 @@ public IActionResult RecordUsage(int subscriptionId)
usageViewModel.MeteredAuditLogs = new List<MeteredAuditLogs>();
usageViewModel.MeteredAuditLogs = this.subscriptionUsageLogsRepository.GetMeteredAuditLogsBySubscriptionId(subscriptionId, true).OrderByDescending(s => s.CreatedDate).ToList();
usageViewModel.DimensionsList = new SelectList(allDimensionsList, "Dimension", "Description");

if (this.saaSApiClientConfiguration.SupportMeteredBilling)
{
this.TempData.Add("SupportMeteredBilling", "1");
this.HttpContext.Session.SetString("SupportMeteredBilling", "1");
}

return this.View(usageViewModel);
}
else
Expand Down
58 changes: 47 additions & 11 deletions src/AdminSite/Controllers/SchedulerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
using System.Web;
using Marketplace.SaaS.Accelerator.DataAccess.Contracts;
using Marketplace.SaaS.Accelerator.DataAccess.Entities;
using Marketplace.SaaS.Accelerator.Services.Configurations;
using Marketplace.SaaS.Accelerator.Services.Models;
using Marketplace.SaaS.Accelerator.Services.Services;
using Marketplace.SaaS.Accelerator.Services.Utilities;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -46,6 +48,11 @@ public class SchedulerController : BaseController
/// </summary>
private readonly IUsersRepository usersRepository;

/// <summary>
/// saaSApiClientConfiguration;
/// </summary>
private SaaSApiClientConfiguration saaSApiClientConfiguration;

/// <summary>
/// Initializes a new instance of the <see cref="PlansController" /> class.
/// </summary>
Expand All @@ -64,14 +71,15 @@ public SchedulerController(ISubscriptionsRepository subscriptionRepository,
ISchedulerManagerViewRepository schedulerViewRepository,
IUsersRepository usersRepository,
SaaSClientLogger<SchedulerController> logger,
ISubscriptionUsageLogsRepository subscriptionUsageLogsRepository,IApplicationConfigRepository applicationConfigRepository)
ISubscriptionUsageLogsRepository subscriptionUsageLogsRepository,IApplicationConfigRepository applicationConfigRepository, SaaSApiClientConfiguration saaSApiClientConfiguration)

{
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.saaSApiClientConfiguration = saaSApiClientConfiguration;

}

Expand All @@ -81,21 +89,36 @@ public SchedulerController(ISubscriptionsRepository subscriptionRepository,
/// <returns>return All subscription.</returns>
public IActionResult Index()
{
this.logger.Info("Scheduler Controller / Get all data");
try
if (this.User.Identity.IsAuthenticated)
{
List<SchedulerManagerViewModel> getAllSchedulerManagerViewData = new List<SchedulerManagerViewModel>();
this.TempData["ShowWelcomeScreen"] = "True";
var currentUserDetail = this.usersRepository.GetPartnerDetailFromEmail(this.CurrentUserEmailAddress);

getAllSchedulerManagerViewData = this.schedulerService.GetAllSchedulerManagerList();
this.logger.Info("Scheduler Controller / Get all data");

return this.View(getAllSchedulerManagerViewData);
try
{
List<SchedulerManagerViewModel> getAllSchedulerManagerViewData = new List<SchedulerManagerViewModel>();
this.TempData["ShowWelcomeScreen"] = "True";
var currentUserDetail = this.usersRepository.GetPartnerDetailFromEmail(this.CurrentUserEmailAddress);

getAllSchedulerManagerViewData = this.schedulerService.GetAllSchedulerManagerList();

if (this.saaSApiClientConfiguration.SupportMeteredBilling)
{
this.TempData.Add("SupportMeteredBilling", "1");
this.HttpContext.Session.SetString("SupportMeteredBilling", "1");
santhoshb-msft marked this conversation as resolved.
Show resolved Hide resolved
}

return this.View(getAllSchedulerManagerViewData);
}
catch (Exception ex)
{
this.logger.LogError($"Message:{ex.Message} :: {ex.InnerException}");
return this.View("Error", ex);
}
}
catch (Exception ex)
else
{
this.logger.LogError($"Message:{ex.Message} :: {ex.InnerException}");
return this.View("Error", ex);
return this.RedirectToAction(nameof(this.Index));
}
}

Expand All @@ -104,6 +127,12 @@ public IActionResult NewScheduler(string subscriptionId, string dimId, string qu
this.logger.Info("New Scheduler Controller");
try
{
if (this.saaSApiClientConfiguration.SupportMeteredBilling)
{
this.TempData.Add("SupportMeteredBilling", "1");
this.HttpContext.Session.SetString("SupportMeteredBilling", "1");
}

SchedulerUsageViewModel schedulerUsageViewModel = new SchedulerUsageViewModel();

this.TempData["ShowWelcomeScreen"] = "True";
Expand Down Expand Up @@ -272,9 +301,16 @@ public IActionResult DeleteSchedulerItem(string id)

public IActionResult SchedulerLogDetail(string id)
{

this.logger.Info(HttpUtility.HtmlEncode($"Scheduler Controller / Get Schedule Item Details: Id {id}"));
try
{
if (this.saaSApiClientConfiguration.SupportMeteredBilling)
{
this.TempData.Add("SupportMeteredBilling", "1");
this.HttpContext.Session.SetString("SupportMeteredBilling", "1");
}

var SchedulerItem = this.schedulerService.GetSchedulerManagerById(int.Parse(id));
var detail = this.schedulerService.GetSchedulerItemRunHistory(int.Parse(id));
SchedulerUsageViewModel schedulerUsageViewModel = new SchedulerUsageViewModel();
Expand Down
9 changes: 6 additions & 3 deletions src/AdminSite/Views/Home/RecordUsage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@
<div class="col-md-2">
<button type="submit" class="cm-button-default mt0">Record Usage</button>
</div>
<div class="col-md-2">
<button name="RedirectBtn2" type="button" onclick="RedirectToScheduler(@Model.SubscriptionDetail.Id);" class="cm-button-default mt0">Add Scheduler Usage</button>
</div>
@if (this.TempData["SupportMeteredBilling"] != null)
{
<div class="col-md-2">
<button name="RedirectBtn2" type="button" onclick="RedirectToScheduler(@Model.SubscriptionDetail.Id);" class="cm-button-default mt0">Add Scheduler Usage</button>
</div>
}
</div>


Expand Down
11 changes: 11 additions & 0 deletions src/AdminSite/Views/Scheduler/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<div class="">
@if (this.TempData["SupportMeteredBilling"] != null)
{
<div class="">
<div class="card-body">
<div class="text-center">
Expand Down Expand Up @@ -107,6 +109,15 @@
}
</div>
</div>
}
else
{

<div >
<h1><span class="cm-section-heading"> Please activate Scheduler feature to access this section</span></h1>
</div>
}

</div>


13 changes: 11 additions & 2 deletions src/AdminSite/Views/Scheduler/NewScheduler.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@

</script>


@if (this.TempData["SupportMeteredBilling"] != null)
{
<div class="container">

<div class="card-body">
Expand Down Expand Up @@ -124,7 +125,15 @@

</form>
</div>


}
else
{

<div >
<h1><span class="cm-section-heading"> Please activate Scheduler feature to access this section</span></h1>

</div>
}

</body>
14 changes: 12 additions & 2 deletions src/AdminSite/Views/Scheduler/SchedulerLogDetail.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
detailModal.style.display = "block";
}
</script>

@if (this.TempData["SupportMeteredBilling"] != null)
{
<div class="card-body">
<div class="modal-header header-bg">
<h1><span class="cm-section-heading"> Activity Log</span></h1>
Expand Down Expand Up @@ -128,4 +129,13 @@

</div>
</div>
</body>
}
else
{

<div>
<h1><span class="cm-section-heading"> Please activate Scheduler feature to access this section</span></h1>

</div>
}
</body>