2020-03-25 23:24:58 +01:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2020-04-04 19:31:01 +02:00
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2020-04-05 00:29:26 +02:00
|
|
|
using Microsoft.AspNetCore.Identity;
|
2020-03-25 23:24:58 +01:00
|
|
|
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-03-25 23:24:58 +01:00
|
|
|
using zero.Core;
|
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-03-25 23:24:58 +01:00
|
|
|
using zero.Web.Controllers;
|
|
|
|
|
|
|
|
|
|
namespace zero.Web.Setup
|
|
|
|
|
{
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public class SetupController : BackofficeController
|
|
|
|
|
{
|
2020-04-03 16:45:47 +02:00
|
|
|
protected ISetupApi Api { get; private set; }
|
2020-03-25 23:24:58 +01:00
|
|
|
|
2020-04-04 19:31:01 +02:00
|
|
|
protected IWebHostEnvironment Environment { get; private set; }
|
2020-04-03 16:45:47 +02:00
|
|
|
|
2020-04-04 19:31:01 +02:00
|
|
|
|
2020-04-05 00:29:26 +02:00
|
|
|
public SetupController(IZeroConfiguration config, ISetupApi api, IWebHostEnvironment env) : 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;
|
2020-03-25 23:24:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
2020-04-04 19:31:01 +02:00
|
|
|
if (!Configuration.ZeroVersion.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Index", "Index");
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-26 22:14:16 +01:00
|
|
|
return View("/Views/Setup.cshtml");
|
2020-03-25 23:24:58 +01: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
|
|
|
}
|
2020-03-25 23:24:58 +01:00
|
|
|
}
|
|
|
|
|
}
|