2022-07-06 05:40:16 +02:00
|
|
|
using System;
|
2022-04-12 09:55:10 +02:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using BTCPayServer.Data;
|
|
|
|
using BTCPayServer.Models.AppViewModels;
|
|
|
|
using BTCPayServer.Services.Apps;
|
|
|
|
using BTCPayServer.Services.Stores;
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Components.AppSales;
|
|
|
|
|
2022-07-06 05:40:16 +02:00
|
|
|
public enum AppSalesPeriod
|
|
|
|
{
|
|
|
|
Week,
|
|
|
|
Month
|
|
|
|
}
|
|
|
|
|
2022-04-12 09:55:10 +02:00
|
|
|
public class AppSales : ViewComponent
|
|
|
|
{
|
|
|
|
private readonly AppService _appService;
|
|
|
|
|
2022-07-06 05:40:16 +02:00
|
|
|
public AppSales(AppService appService)
|
2022-04-12 09:55:10 +02:00
|
|
|
{
|
|
|
|
_appService = appService;
|
|
|
|
}
|
|
|
|
|
2022-07-06 05:40:16 +02:00
|
|
|
public async Task<IViewComponentResult> InvokeAsync(AppSalesViewModel vm)
|
2022-04-12 09:55:10 +02:00
|
|
|
{
|
2022-07-06 05:40:16 +02:00
|
|
|
if (vm.App == null) throw new ArgumentNullException(nameof(vm.App));
|
|
|
|
if (vm.InitialRendering) return View(vm);
|
|
|
|
|
|
|
|
var stats = await _appService.GetSalesStats(vm.App);
|
|
|
|
|
|
|
|
vm.SalesCount = stats.SalesCount;
|
|
|
|
vm.Series = stats.Series;
|
2022-04-12 09:55:10 +02:00
|
|
|
|
|
|
|
return View(vm);
|
|
|
|
}
|
|
|
|
}
|