Files
mixtape/zero.Web/Controllers/SetupController.cs
T

57 lines
1.2 KiB
C#
Raw Normal View History

2020-04-15 14:09:52 +02:00
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
2020-04-03 18:03:36 +02:00
using System;
using System.Linq;
2020-03-30 17:11:56 +02:00
using System.Threading.Tasks;
2020-04-03 16:45:47 +02:00
using zero.Core.Api;
using zero.Core.Entities;
2020-03-30 17:11:56 +02:00
using zero.Core.Entities.Setup;
2020-04-04 19:31:01 +02:00
using zero.Core.Extensions;
2020-04-16 00:56:22 +02:00
using zero.Core.Identity;
using zero.Web.Controllers;
namespace zero.Web.Setup
{
2020-04-15 14:09:52 +02:00
[ZeroAuthorize(false)]
public class SetupController : BackofficeController
{
ISetupApi Api;
IWebHostEnvironment Env;
2020-04-04 19:31:01 +02:00
public SetupController(ISetupApi api, IWebHostEnvironment env)
2020-04-03 16:45:47 +02:00
{
Api = api;
Env = env;
}
2020-04-15 14:09:52 +02:00
public IActionResult Index()
{
if (!Options.ZeroVersion.IsNullOrEmpty())
2020-04-04 19:31:01 +02:00
{
return Redirect(Options.BackofficePath);
2020-04-04 19:31:01 +02:00
}
2020-03-26 22:14:16 +01:00
return View("/Views/Setup.cshtml");
}
2020-03-30 17:11:56 +02:00
2020-04-15 14:09:52 +02:00
2020-03-30 17:11:56 +02:00
[HttpPost]
2020-04-03 16:45:47 +02:00
public async Task<IActionResult> Install([FromBody] SetupModel model)
2020-03-30 17:11:56 +02:00
{
model.ContentRootPath = Env.ContentRootPath;
2020-04-04 19:31:01 +02:00
2020-04-15 15:13:38 +02:00
EntityResult<SetupModel> result = await Api.Install(model);
2020-04-03 18:03:36 +02:00
if (result.IsSuccess)
{
return Json(result);
}
object value = String.Join("\n\n", result.Errors.Select(error => error.Message + "\n(property: " + error.Property + ")"));
return StatusCode(500, value);
2020-03-30 17:11:56 +02:00
}
}
}