Server und Container Overview+Add Seite erstellt und an Datenbank angeschlossen

This commit is contained in:
2025-06-15 00:56:40 +02:00
parent 1597409365
commit b3902d971c
17 changed files with 636 additions and 3 deletions

View File

@@ -0,0 +1,56 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Watcher.Data;
using Watcher.Models;
using Watcher.ViewModels;
[Authorize]
public class ServerController : Controller
{
private readonly AppDbContext _context;
public ServerController(AppDbContext context)
{
_context = context;
}
public async Task<IActionResult> Overview()
{
var vm = new ServerOverviewViewModel
{
Servers = await _context.Servers.OrderBy(s => s.Id).ToListAsync()
};
return View(vm);
}
[HttpGet]
public IActionResult AddServer()
{
return View();
}
[HttpPost]
public async Task<IActionResult> AddServer(AddServerViewModel vm)
{
if (!ModelState.IsValid)
return View(vm);
var server = new Server
{
Name = vm.Name,
IPAddress = vm.IPAddress,
Hostname = vm.Hostname,
Status = vm.Status,
Type = vm.Type,
IsOnline = vm.IsOnline,
CreatedAt = DateTime.UtcNow
};
_context.Servers.Add(server);
await _context.SaveChangesAsync();
return RedirectToAction("Overview");
}
}