parent
bd853857e0
commit
5e36b68090
Binary file not shown.
@ -1,56 +1,52 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Application.Domain.Entities;
|
||||
using Infrastructure.Data;
|
||||
using Infrastructure.Jwt;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace IoTCenter.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly IJwtHelper _jwtHelper;
|
||||
private readonly IRepository<Node> _nodeRepo;
|
||||
private readonly IRepository<Device> _deviceRepo;
|
||||
|
||||
public HomeController(IJwtHelper jwtHelper, IRepository<Node> nodeRepo, IRepository<Device> deviceRepo)
|
||||
public HomeController(IRepository<Node> nodeRepo, IRepository<Device> deviceRepo)
|
||||
{
|
||||
this._jwtHelper = jwtHelper;
|
||||
this._nodeRepo = nodeRepo;
|
||||
this._deviceRepo = deviceRepo;
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult GetNodes(string token)
|
||||
public IActionResult GetNodes()
|
||||
{
|
||||
var userName = this._jwtHelper.GetPayload(token)["UserName"].ToString();
|
||||
var model = this._nodeRepo.ReadOnlyTable()
|
||||
.Select(o => new { o.Number, o.Name, o.DisplayOrder, Count = o.Devices.Count })
|
||||
.Include(o => o.Devices)
|
||||
.ToList();
|
||||
return Json(model);
|
||||
return Json(model, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public IActionResult Node(Guid id)
|
||||
{
|
||||
var model = this._nodeRepo.ReadOnlyTable().FirstOrDefault(o => o.Id == id);
|
||||
return View(model);
|
||||
}
|
||||
|
||||
public IActionResult GetNode(string number)
|
||||
public IActionResult GetNode(Guid id)
|
||||
{
|
||||
var model = this._nodeRepo.ReadOnlyTable()
|
||||
.Include(o => o.Sences)
|
||||
.Include(o => o.Devices).ThenInclude(o => o.Data)
|
||||
.FirstOrDefault(o => o.Number == number);
|
||||
.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 });
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue