You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.7 KiB
53 lines
1.7 KiB
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<Node> _nodeRepo;
|
|
private readonly IRepository<Device> _deviceRepo;
|
|
|
|
public HomeController(IRepository<Node> nodeRepo, IRepository<Device> 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 });
|
|
}
|
|
}
|
|
} |