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

63 lines
1.6 KiB
C#
Raw Normal View History

2020-04-15 14:09:52 +02:00
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
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;
using zero.Core;
2020-04-03 16:45:47 +02:00
using zero.Core.Api;
2020-04-15 14:09:52 +02:00
using zero.Core.Auth;
2020-04-03 16:45:47 +02:00
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;
using zero.Web.Controllers;
namespace zero.Web.Setup
{
2020-04-15 14:09:52 +02:00
[ZeroAuthorize(false)]
public class SetupController : BackofficeController
{
2020-04-03 16:45:47 +02:00
protected ISetupApi Api { get; private set; }
2020-04-04 19:31:01 +02:00
protected IWebHostEnvironment Environment { get; private set; }
2020-04-03 16:45:47 +02:00
protected ZeroOptions Options { get; private set; }
2020-04-04 19:31:01 +02:00
public SetupController(IZeroConfiguration config, ISetupApi api, IWebHostEnvironment env, IOptionsMonitor<ZeroOptions> options) : base(config) // UserManager<User> userManager
2020-04-03 16:45:47 +02:00
{
Api = api;
2020-04-04 19:31:01 +02:00
Environment = env;
Options = options.CurrentValue;
}
2020-04-15 14:09:52 +02:00
public IActionResult Index()
{
2020-04-04 19:31:01 +02:00
if (!Configuration.ZeroVersion.IsNullOrEmpty())
{
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
{
2020-04-04 19:31:01 +02:00
model.ContentRootPath = Environment.ContentRootPath;
2020-04-03 16:45:47 +02:00
EntityChangeResult<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
}
}
}