49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using PlotLine.Services;
|
|
using PlotLine.ViewModels;
|
|
|
|
namespace PlotLine.Controllers;
|
|
|
|
public sealed class PlotLinesController(IPlotService plots) : Controller
|
|
{
|
|
public async Task<IActionResult> Index(int projectId)
|
|
{
|
|
var model = await plots.GetPlotLinesAsync(projectId);
|
|
return model is null ? NotFound() : View(model);
|
|
}
|
|
|
|
public async Task<IActionResult> Create(int projectId)
|
|
{
|
|
var model = await plots.GetCreatePlotLineAsync(projectId);
|
|
return model is null ? NotFound() : View("Edit", model);
|
|
}
|
|
|
|
public async Task<IActionResult> Edit(int id)
|
|
{
|
|
var model = await plots.GetEditPlotLineAsync(id);
|
|
return model is null ? NotFound() : View(model);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> Save(PlotLineEditViewModel model)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return View("Edit", model);
|
|
}
|
|
|
|
await plots.SavePlotLineAsync(model);
|
|
return RedirectToAction(nameof(Index), new { projectId = model.ProjectID });
|
|
}
|
|
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> Archive(int id, int projectId)
|
|
{
|
|
await plots.ArchivePlotLineAsync(id);
|
|
TempData["ArchiveMessage"] = "Plot line archived. You can restore it from Archived Items.";
|
|
return RedirectToAction(nameof(Index), new { projectId });
|
|
}
|
|
}
|