PlotDirector/PlotLine/Controllers/StoryAssetsController.cs
2026-06-01 09:03:59 +01:00

70 lines
2.0 KiB
C#

using Microsoft.AspNetCore.Mvc;
using PlotLine.Services;
using PlotLine.ViewModels;
namespace PlotLine.Controllers;
public sealed class StoryAssetsController(IAssetService assets) : Controller
{
public async Task<IActionResult> Index(int projectId)
{
var model = await assets.GetAssetsAsync(projectId);
return model is null ? NotFound() : View(model);
}
public async Task<IActionResult> Create(int projectId)
{
var model = await assets.GetCreateAssetAsync(projectId);
return model is null ? NotFound() : View("Edit", model);
}
public async Task<IActionResult> Edit(int id)
{
var model = await assets.GetEditAssetAsync(id);
return model is null ? NotFound() : View(model);
}
public async Task<IActionResult> Details(int id)
{
var model = await assets.GetAssetDetailAsync(id);
return model is null ? NotFound() : View(model);
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Save(StoryAssetEditViewModel model)
{
if (!ModelState.IsValid)
{
return View("Edit", model);
}
var assetId = await assets.SaveAssetAsync(model);
return RedirectToAction(nameof(Details), new { id = assetId });
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Archive(int id, int projectId)
{
await assets.ArchiveAssetAsync(id);
return RedirectToAction(nameof(Index), new { projectId });
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> AddDependency(AssetDependencyEditViewModel model, int returnAssetId)
{
await assets.SaveDependencyAsync(model);
return RedirectToAction(nameof(Details), new { id = returnAssetId });
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteDependency(int id, int returnAssetId)
{
await assets.DeleteDependencyAsync(id);
return RedirectToAction(nameof(Details), new { id = returnAssetId });
}
}