using Application.Domain.Entities; using Infrastructure.Application.Services.Settings; using Infrastructure.Data; using Infrastructure.Web; using IoT.Shared.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using System.Linq; using System.Reflection; namespace IoTNode.Controllers { //[Device] public class HomeController : BaseController { private readonly ISettingService _settingService; private readonly IRepository _nodeRepo; private readonly IRepository _sceneRepo; private readonly IoTNodeClient _ioTNodeClient; public HomeController(ISettingService settingService, IRepository nodeRepo, IRepository sceneRepo, IoTNodeClient ioTNodeClient) { this._settingService = settingService; this._nodeRepo = nodeRepo; this._sceneRepo = sceneRepo; this._ioTNodeClient = ioTNodeClient; } [Authorize] public IActionResult Index() { var model = this._nodeRepo.ReadOnlyTable().Include(o => o.Devices).ThenInclude(o => o.Product).FirstOrDefault(); return View(model); } public IActionResult Scenes() { var model = this._sceneRepo.ReadOnlyTable() .Include(o => o.SceneTimers) .Include(o => o.SceneTiggers) .Include(o => o.SceneCommands).ThenInclude(o => o.Command).ThenInclude(o => o.Device) .Include(o => o.SceneCommands).ThenInclude(o => o.Command).ThenInclude(o => o.Api) .ToList(); return View(model); } public IActionResult Upload() { this._ioTNodeClient.OnConnected(); return RedirectTo(); } public IActionResult GetVersion() { return Content(Assembly.GetEntryAssembly().GetCustomAttribute().InformationalVersion); } public IActionResult GetServer() { return Content(this._settingService.GetSetting("notify:host").Value?.Trim()); } } }