2020-04-15 14:09:52 +02:00
|
|
|
using Microsoft.AspNetCore.Hosting;
|
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-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;
|
2020-10-27 15:47:23 +01:00
|
|
|
using zero.Core.Options;
|
2020-03-25 23:24:58 +01:00
|
|
|
|
|
|
|
|
namespace zero.Web.Setup
|
|
|
|
|
{
|
2020-04-15 14:09:52 +02:00
|
|
|
[ZeroAuthorize(false)]
|
2020-10-27 15:47:23 +01:00
|
|
|
public class ZeroSetupController : Controller
|
2020-03-25 23:24:58 +01:00
|
|
|
{
|
2020-05-11 15:34:47 +02:00
|
|
|
ISetupApi Api;
|
|
|
|
|
IWebHostEnvironment Env;
|
2020-10-27 15:47:23 +01:00
|
|
|
IZeroOptions Options;
|
2020-04-04 19:31:01 +02:00
|
|
|
|
2020-04-05 13:05:39 +02:00
|
|
|
|
2020-10-27 15:47:23 +01:00
|
|
|
public ZeroSetupController(ISetupApi api, IWebHostEnvironment env, IZeroOptions options)
|
2020-04-03 16:45:47 +02:00
|
|
|
{
|
|
|
|
|
Api = api;
|
2020-05-11 15:34:47 +02:00
|
|
|
Env = env;
|
2020-10-27 15:47:23 +01:00
|
|
|
Options = options;
|
2020-03-25 23:24:58 +01:00
|
|
|
}
|
|
|
|
|
|
2020-04-15 14:09:52 +02:00
|
|
|
|
2020-03-25 23:24:58 +01:00
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
2020-12-02 15:45:44 +01:00
|
|
|
//if (!Options.ZeroVersion.IsNullOrEmpty())
|
|
|
|
|
//{
|
|
|
|
|
// return Redirect(Options.BackofficePath);
|
|
|
|
|
//}
|
2020-04-04 19:31:01 +02:00
|
|
|
|
2020-10-27 15:47:23 +01:00
|
|
|
return View("/Views/Zero/Setup.cshtml");
|
2020-03-25 23:24:58 +01:00
|
|
|
}
|
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-05-11 15:34:47 +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
|
|
|
}
|
2020-03-25 23:24:58 +01:00
|
|
|
}
|
|
|
|
|
}
|