CRUD-Operation für Server implementiert
This commit is contained in:
@@ -41,11 +41,8 @@ public class ServerController : Controller
|
||||
{
|
||||
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);
|
||||
@@ -53,4 +50,57 @@ public class ServerController : Controller
|
||||
|
||||
return RedirectToAction("Overview");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> Delete(int id)
|
||||
{
|
||||
var server = await _context.Servers.FindAsync(id);
|
||||
if (server == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
_context.Servers.Remove(server);
|
||||
await _context.SaveChangesAsync();
|
||||
return RedirectToAction(nameof(Overview));
|
||||
}
|
||||
|
||||
// GET: Server/Edit/5
|
||||
public async Task<IActionResult> EditServer(int id)
|
||||
{
|
||||
var server = await _context.Servers.FindAsync(id);
|
||||
if (server == null) return NotFound();
|
||||
|
||||
var vm = new EditServerViewModel
|
||||
{
|
||||
Name = server.Name,
|
||||
IPAddress = server.IPAddress,
|
||||
Type = server.Type
|
||||
};
|
||||
|
||||
return View(vm);
|
||||
}
|
||||
|
||||
// POST: Server/Edit/5
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> EditServer(int id, EditServerViewModel vm)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var server = await _context.Servers.FindAsync(id);
|
||||
if (server == null) return NotFound();
|
||||
|
||||
server.Name = vm.Name;
|
||||
server.IPAddress = vm.IPAddress;
|
||||
server.Type = vm.Type;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
return RedirectToAction(nameof(Overview));
|
||||
}
|
||||
|
||||
return View(vm);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user