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.
iot/projects/IoT/IoT.Shared/Controllers/AjaxController.cs

101 lines
3.1 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using Application.Domain.Entities;
using Infrastructure.Data;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace IoTShared.Controllers
{
[Area("Admin")]
public class AjaxController
{
private readonly ILogger<AjaxController> _logger;
private readonly IRepository<Node> _nodeRepo;
private readonly IRepository<Sence> _senceRepo;
private readonly IRepository<Device> _deviceRepo;
private readonly IRepository<Api> _apiRepo;
public AjaxController(ILogger<AjaxController> logger,
IRepository<Node> nodeRepo,
IRepository<Sence> senceRepo,
IRepository<Device> deviceRepo,
IRepository<Api> apiRepo)
{
this._logger = logger;
this._nodeRepo = nodeRepo;
this._senceRepo = senceRepo;
this._deviceRepo = deviceRepo;
this._apiRepo = apiRepo;
}
#region Node
public SelectList GetNodeSelectList(Guid? selected = null)
{
var list = this._nodeRepo.ReadOnlyTable()
.Select(o => new { o.Id, Name = $"{o.Name}/{o.Number}" })
.ToList();
return new SelectList(list, "Id", "Name", selected);
}
#endregion Node
#region Sence
public SelectList GetSenceSelectList(Guid parentId, Guid? selected = null)
{
var list = this._senceRepo.ReadOnlyTable()
.Where(o => o.NodeId == parentId)
.Select(o => new { o.Id, o.Name })
.ToList();
return new SelectList(list, "Id", "Name", selected);
}
public JsonResult GetSenceJson(Guid parentId, Guid? selected)
{
return new JsonResult(this.GetSenceSelectList(parentId, selected));
}
#endregion Sence
#region Device
public SelectList GetDeviceSelectList(Guid parentId, Guid? selected = null)
{
var list = this._deviceRepo.ReadOnlyTable()
.Where(o => o.NodeId == parentId)
.Select(o => new { o.Id, Name = $"{o.DisplayName}/{o.Number}" })
.ToList();
return new SelectList(list, "Id", "Name", selected);
}
public JsonResult GetDeviceJson(Guid parentId, Guid? selected)
{
return new JsonResult(this.GetDeviceSelectList(parentId, selected));
}
#endregion Device
#region Api
public SelectList GetApiSelectList(Guid parentId, Guid? selected = null)
{
var list = this._apiRepo.ReadOnlyTable()
//.Where(o => o.DeviceId == parentId)
.Select(o => new { o.Id, o.Name })
.ToList();
return new SelectList(list, "Id", "Name", selected);
}
public JsonResult GetApiJson(Guid parentId, Guid? selected)
{
return new JsonResult(this.GetApiSelectList(parentId, selected));
}
#endregion Api
}
}