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.
67 lines
2.5 KiB
67 lines
2.5 KiB
using Infrastructure.Data;
|
|
using Application.Domain.Entities;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace IoT.Shared.Areas.IoTCenter.Controlls
|
|
{
|
|
public class AjaxBaseController
|
|
{
|
|
protected readonly IServiceProvider _services;
|
|
|
|
protected readonly ILogger<AjaxBaseController> _logger;
|
|
|
|
public AjaxBaseController(IServiceProvider services, ILogger<AjaxBaseController> logger)
|
|
{
|
|
this._services = services;
|
|
this._logger = logger;
|
|
}
|
|
|
|
public JsonResult GetIoTProduct(Guid? selected)
|
|
{
|
|
using var scope = this._services.CreateScope();
|
|
var repo = scope.ServiceProvider.GetRequiredService<IRepository<IoTProduct>>();
|
|
var list = repo.ReadOnlyTable()
|
|
.Select(o => new { o.Id, o.Name })
|
|
.ToList();
|
|
return new JsonResult(new SelectList(list, "Id", "Name", selected));
|
|
}
|
|
|
|
public JsonResult GetIoTApi(Guid parentId, Guid? selected = null)
|
|
{
|
|
using var scope = this._services.CreateScope();
|
|
var repo = scope.ServiceProvider.GetRequiredService<IRepository<IoTApi>>();
|
|
var list = repo.ReadOnlyTable()
|
|
.Where(o => o.IoTProductId == parentId)
|
|
.Select(o => new { o.Id, o.Name })
|
|
.ToList();
|
|
return new JsonResult(new SelectList(list, "Id", "Name", selected));
|
|
}
|
|
|
|
public JsonResult GetIoTGateway(Guid? selected = null)
|
|
{
|
|
using var scope = this._services.CreateScope();
|
|
var repo = scope.ServiceProvider.GetRequiredService<IRepository<IoTGateway>>();
|
|
var list = repo.ReadOnlyTable()
|
|
.Select(o => new { o.Id, Name = $"[{o.Number}]{o.Name}" })
|
|
.ToList();
|
|
return new JsonResult(new SelectList(list, "Id", "Name", selected));
|
|
}
|
|
|
|
public JsonResult GetIoTDevice(Guid parentId, Guid? selected = null)
|
|
{
|
|
using var scope = this._services.CreateScope();
|
|
var repo = scope.ServiceProvider.GetRequiredService<IRepository<IoTDevice>>();
|
|
var list = repo.ReadOnlyTable()
|
|
.Where(o => o.IoTGatewayId == parentId)
|
|
.Select(o => new { o.Id, o.Name })
|
|
.ToList();
|
|
return new JsonResult(new SelectList(list, "Id", "Name", selected));
|
|
}
|
|
}
|
|
}
|