1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-10 15:20:48 -05:00

update controllers to use DI stat manager

This commit is contained in:
RaidMax
2023-04-04 22:10:37 -05:00
parent 4008d12d0d
commit cd98ddcb55
4 changed files with 55 additions and 52 deletions

View File

@ -3,6 +3,7 @@ using System.Threading.Tasks;
using IW4MAdmin.Plugins.Stats;
using IW4MAdmin.Plugins.Stats.Helpers;
using Microsoft.AspNetCore.Mvc;
using SharedLibraryCore.Interfaces;
using Stats.Config;
namespace WebfrontCore.ViewComponents
@ -10,26 +11,28 @@ namespace WebfrontCore.ViewComponents
public class TopPlayersViewComponent : ViewComponent
{
private readonly StatsConfiguration _config;
private readonly StatManager _statManager;
public TopPlayersViewComponent(StatsConfiguration config)
public TopPlayersViewComponent(StatsConfiguration config, StatManager statManager)
{
_config = config;
_statManager = statManager;
}
public async Task<IViewComponentResult> InvokeAsync(int count, int offset, string serverEndpoint = null)
{
var server = Plugin.ServerManager.GetServers()
.FirstOrDefault(server => server.ToString() == serverEndpoint);
.FirstOrDefault(server => server.Id == serverEndpoint) as IGameServer;
var serverId = server is null ? (long?)null : StatManager.GetIdForServer(server);
var serverId = server?.LegacyDatabaseId;
ViewBag.UseNewStats = _config?.EnableAdvancedMetrics ?? true;
ViewBag.SelectedServerName = server?.Hostname;
ViewBag.SelectedServerName = server?.ServerName;
return View("~/Views/Client/Statistics/Components/TopPlayers/_List.cshtml",
ViewBag.UseNewStats
? await Plugin.Manager.GetNewTopStats(offset, count, serverId)
: await Plugin.Manager.GetTopStats(offset, count, serverId));
? await _statManager.GetNewTopStats(offset, count, serverId)
: await _statManager.GetTopStats(offset, count, serverId));
}
}
}