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