38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using PlotLine.Services;
|
|
using PlotLine.ViewModels;
|
|
|
|
namespace PlotLine.Controllers;
|
|
|
|
public sealed class ImportsController(IImportService imports) : Controller
|
|
{
|
|
public IActionResult Index() => View(new ImportIndexViewModel
|
|
{
|
|
JsonText = ImportIndexViewModel.SampleJson
|
|
});
|
|
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> Preview(ImportIndexViewModel model)
|
|
{
|
|
model = await imports.PreviewAsync(model);
|
|
return View("Index", model);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> Import(ImportIndexViewModel model)
|
|
{
|
|
var result = await imports.ImportAsync(model);
|
|
if (result.Succeeded && result.ProjectID.HasValue)
|
|
{
|
|
TempData["ImportMessage"] = result.Message;
|
|
return RedirectToAction("Details", "Projects", new { id = result.ProjectID.Value });
|
|
}
|
|
|
|
model.Preview ??= (await imports.PreviewAsync(model)).Preview;
|
|
model.StatusMessage = result.Message;
|
|
return View("Index", model);
|
|
}
|
|
}
|