58 lines
1.6 KiB
C#
58 lines
1.6 KiB
C#
using System.Diagnostics;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using watcher_monitoring.Models;
|
|
|
|
using watcher_monitoring.Data;
|
|
using watcher_monitoring.ViewModels;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace watcher_monitoring.Controllers;
|
|
|
|
[Authorize]
|
|
public class HomeController : Controller
|
|
{
|
|
private readonly WatcherDbContext _context;
|
|
private readonly ILogger<HomeController> _logger;
|
|
|
|
public HomeController(ILogger<HomeController> logger, WatcherDbContext dbContext)
|
|
{
|
|
_logger = logger;
|
|
_context = dbContext;
|
|
}
|
|
|
|
// Dashboard
|
|
public async Task<IActionResult> Index()
|
|
{
|
|
List<Server> _servers = await _context.Servers.ToListAsync();
|
|
List<Container> _containers = await _context.Containers.ToListAsync();
|
|
|
|
var homeVm = new HomeViewModel
|
|
{
|
|
servers = _servers,
|
|
containers = _containers,
|
|
serversCount = _servers.Count,
|
|
serversOnline = (from server in _servers where server.IsOnline select server).Count(),
|
|
serversOffline = _servers.Count - (from server in _servers where server.IsOnline select server).Count()
|
|
};
|
|
|
|
return View(homeVm);
|
|
}
|
|
|
|
public IActionResult Privacy()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
public IActionResult SystemInformation()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public IActionResult Error()
|
|
{
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
}
|
|
}
|