using System; using System.Linq; using Application.Domain.Entities; using Infrastructure.Data; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; namespace IoTCenter.Controllers { [Authorize] public class HomeController : Controller { private readonly IRepository _nodeRepo; private readonly IRepository _deviceRepo; public HomeController(IRepository nodeRepo, IRepository deviceRepo) { this._nodeRepo = nodeRepo; this._deviceRepo = deviceRepo; } public IActionResult Index() { return View(); } public IActionResult GetNodes() { var model = this._nodeRepo.ReadOnlyTable() .Include(o => o.Devices) .ToList(); return Json(model, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); } public IActionResult Node(Guid id) { var model = this._nodeRepo.ReadOnlyTable().FirstOrDefault(o => o.Id == id); return View(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 }); } } }