using Application.Domain.Entities; using Infrastructure.Data; using Infrastructure.Extensions; using Infrastructure.Web; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; using System; using System.Linq; namespace IoTNode.Controllers { [Device] public class HomeController : Controller { private readonly IRepository _nodeRepo; private readonly IRepository _deviceRepo; public HomeController(IRepository nodeRepo, IRepository deviceRepo) { this._nodeRepo = nodeRepo; this._deviceRepo = deviceRepo; } [Authorize] public IActionResult Index() { var model = this._nodeRepo.ReadOnlyTable().FirstOrDefault(); return View(); } public IActionResult GetNode(Guid id) { var model = this._nodeRepo.ReadOnlyTable() .Include(o => o.Scenes) .Include(o => o.Devices).ThenInclude(o => o.Data) .FirstOrDefault(o => o.Id == id); return Json(model, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); } public IActionResult Update() { try { return Content(""); } catch (Exception ex) { ex.PrintStack(); return Content(ex.Message); } } public IActionResult Test() { return View(); } } }