70 lines
2.1 KiB
C#
70 lines
2.1 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using PlotLine.Services;
|
|
using PlotLine.ViewModels;
|
|
|
|
namespace PlotLine.Controllers;
|
|
|
|
public sealed class LocationsController(ILocationService locations) : Controller
|
|
{
|
|
public async Task<IActionResult> Index(int projectId)
|
|
{
|
|
var model = await locations.GetLocationsAsync(projectId);
|
|
return model is null ? NotFound() : View(model);
|
|
}
|
|
|
|
public async Task<IActionResult> Create(int projectId)
|
|
{
|
|
var model = await locations.GetCreateAsync(projectId);
|
|
return model is null ? NotFound() : View("Edit", model);
|
|
}
|
|
|
|
public async Task<IActionResult> Edit(int id)
|
|
{
|
|
var model = await locations.GetEditAsync(id);
|
|
return model is null ? NotFound() : View(model);
|
|
}
|
|
|
|
public async Task<IActionResult> Details(int id)
|
|
{
|
|
var model = await locations.GetDetailAsync(id);
|
|
return model is null ? NotFound() : View(model);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> Save(LocationEditViewModel model)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return View("Edit", model);
|
|
}
|
|
|
|
var locationId = await locations.SaveAsync(model);
|
|
return RedirectToAction(nameof(Details), new { id = locationId });
|
|
}
|
|
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> Archive(int id, int projectId)
|
|
{
|
|
await locations.ArchiveAsync(id);
|
|
return RedirectToAction(nameof(Index), new { projectId });
|
|
}
|
|
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> AddRelationship(LocationRelationshipEditViewModel model)
|
|
{
|
|
await locations.SaveRelationshipAsync(model);
|
|
return RedirectToAction(nameof(Details), new { id = model.FromLocationID });
|
|
}
|
|
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> ArchiveRelationship(int id, int returnLocationId)
|
|
{
|
|
await locations.ArchiveRelationshipAsync(id);
|
|
return RedirectToAction(nameof(Details), new { id = returnLocationId });
|
|
}
|
|
}
|