PlotDirector/PlotLine/Controllers/ProjectRestorePointsController.cs
2026-06-05 16:15:49 +01:00

55 lines
2.2 KiB
C#

using Microsoft.AspNetCore.Mvc;
using PlotLine.Services;
namespace PlotLine.Controllers;
public sealed class ProjectRestorePointsController(IProjectRestorePointService restorePoints, ILogger<ProjectRestorePointsController> logger) : Controller
{
public async Task<IActionResult> Index(int projectId)
{
var model = await restorePoints.GetAsync(projectId);
return model is null ? NotFound() : View(model);
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(int projectId, string? restorePointName, string? notes)
{
try
{
var created = await restorePoints.CreateManualAsync(projectId, restorePointName, notes);
TempData["ProjectRestorePointMessage"] = created is null
? "Restore point could not be created because the project was not found."
: "Restore point created.";
}
catch (Exception ex)
{
logger.LogError(ex, "Manual restore point creation failed for project {ProjectID}.", projectId);
TempData["ProjectRestorePointMessage"] = "Restore point could not be created. Please try again, or check the application logs if the problem continues.";
}
return RedirectToAction(nameof(Index), new { projectId });
}
public async Task<IActionResult> Download(int projectId, int id)
{
try
{
var download = await restorePoints.DownloadAsync(id, projectId);
if (download is null)
{
TempData["ProjectRestorePointMessage"] = "Restore point could not be found.";
return RedirectToAction(nameof(Index), new { projectId });
}
return File(System.Text.Encoding.UTF8.GetBytes(download.Json), download.ContentType, download.FileName);
}
catch (Exception ex)
{
logger.LogError(ex, "Restore point download failed for restore point {ProjectRestorePointID} in project {ProjectID}.", id, projectId);
TempData["ProjectRestorePointMessage"] = "Restore point could not be downloaded. Please try again, or check the application logs if the problem continues.";
return RedirectToAction(nameof(Index), new { projectId });
}
}
}