2022-06-28 07:05:02 +02:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
2022-04-12 09:55:10 +02:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using BTCPayServer.Data;
|
|
|
|
using BTCPayServer.Services.Apps;
|
|
|
|
using BTCPayServer.Services.Stores;
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Components.AppTopItems;
|
|
|
|
|
|
|
|
public class AppTopItems : ViewComponent
|
|
|
|
{
|
|
|
|
private readonly AppService _appService;
|
|
|
|
|
2022-07-06 05:40:16 +02:00
|
|
|
public AppTopItems(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(AppTopItemsViewModel 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 entries = Enum.Parse<AppType>(vm.App.AppType) == AppType.Crowdfund
|
|
|
|
? await _appService.GetPerkStats(vm.App)
|
|
|
|
: await _appService.GetItemStats(vm.App);
|
|
|
|
|
|
|
|
vm.Entries = entries.ToList();
|
2022-04-12 09:55:10 +02:00
|
|
|
|
|
|
|
return View(vm);
|
|
|
|
}
|
|
|
|
}
|