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 _logger; private readonly IHostApplicationLifetime _appLifetime; public AdminController(IWebHostEnvironment env, ILogger 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().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"); } } }