You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.6 KiB
49 lines
1.6 KiB
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using System.IO;
|
|
|
|
namespace SiteLibrary.Controllers
|
|
{
|
|
public class AdminController : Controller
|
|
{
|
|
private readonly IWebHostEnvironment _env;
|
|
private readonly ILogger<AdminController> _logger;
|
|
private readonly IHostApplicationLifetime _appLifetime;
|
|
|
|
public AdminController(IWebHostEnvironment env, ILogger<AdminController> logger, IHostApplicationLifetime appLifetime)
|
|
{
|
|
this._env = env;
|
|
this._logger = logger;
|
|
this._appLifetime = appLifetime;
|
|
}
|
|
|
|
public IActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
public IActionResult UpdateDB()
|
|
{
|
|
using var db = new MyDbContext(new DbContextOptionsBuilder<MyDbContext>().UseSqlite($"Data Source={Path.Combine(this._env.WebRootPath, "data.db")}").Options);
|
|
db.Seed(this._env.WebRootPath, false, o => this._logger.LogInformation(o), o => this._logger.LogError(o));
|
|
this._env.WebRootPath.UpdateList(o => this._logger.LogInformation(o));
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
public IActionResult UpdateList()
|
|
{
|
|
this._env.WebRootPath.UpdateList(o => this._logger.LogInformation(o));
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
public IActionResult Restart()
|
|
{
|
|
this._appLifetime.StopApplication();
|
|
return RedirectToAction("Index");
|
|
}
|
|
}
|
|
}
|