using Microsoft.AspNetCore.Mvc; using PlotLine.Services; using PlotLine.ViewModels; namespace PlotLine.Controllers; public sealed class PlotThreadsController(IPlotService plots) : Controller { public async Task Index(int projectId) { var model = await plots.GetPlotThreadsAsync(projectId); return model is null ? NotFound() : View(model); } public async Task Create(int projectId, int? plotLineId) { var model = await plots.GetCreatePlotThreadAsync(projectId, plotLineId); return model is null ? NotFound() : View("Edit", model); } public async Task Edit(int id) { var model = await plots.GetEditPlotThreadAsync(id); return model is null ? NotFound() : View(model); } [HttpPost] [ValidateAntiForgeryToken] public async Task Save(PlotThreadEditViewModel model) { if (!ModelState.IsValid) { return View("Edit", model); } await plots.SavePlotThreadAsync(model); return RedirectToAction(nameof(Index), new { projectId = model.ProjectID }); } [HttpPost] [ValidateAntiForgeryToken] public async Task Archive(int id, int projectId) { await plots.ArchivePlotThreadAsync(id); return RedirectToAction(nameof(Index), new { projectId }); } }