PlotDirector/PlotLine/Controllers/ProjectsController.cs
Nick Beckley 04a41e81b0 Phase 1T
2026-06-01 15:42:44 +01:00

47 lines
1.3 KiB
C#

using Microsoft.AspNetCore.Mvc;
using PlotLine.Services;
using PlotLine.ViewModels;
namespace PlotLine.Controllers;
public sealed class ProjectsController(IProjectService projects) : Controller
{
public async Task<IActionResult> Index() => View(await projects.ListAsync());
public async Task<IActionResult> Details(int id)
{
var model = await projects.GetDetailAsync(id);
return model is null ? NotFound() : View(model);
}
public IActionResult Create() => View("Edit", new ProjectEditViewModel());
public async Task<IActionResult> Edit(int id)
{
var model = await projects.GetEditAsync(id);
return model is null ? NotFound() : View(model);
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Save(ProjectEditViewModel model)
{
if (!ModelState.IsValid)
{
return View("Edit", model);
}
var projectId = await projects.SaveAsync(model);
return RedirectToAction(nameof(Details), new { id = projectId });
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Archive(int id)
{
await projects.ArchiveAsync(id);
TempData["ArchiveMessage"] = "Project archived. You can restore it from Archived Items.";
return RedirectToAction(nameof(Index));
}
}