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.
90 lines
3.6 KiB
90 lines
3.6 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 GetDictionaryCategory(Guid? selected)
|
|
{
|
|
using var scope = this._services.CreateScope();
|
|
var repo = scope.ServiceProvider.GetRequiredService<IRepository<DictionaryCategory>>();
|
|
var list = repo.ReadOnlyTable()
|
|
.Select(o => new { o.Name, Value=o.Key })
|
|
.ToList();
|
|
return new JsonResult(new SelectList(list, "Value", "Name", selected));
|
|
}
|
|
public JsonResult GetDictionary(string key,string selected)
|
|
{
|
|
using var scope = this._services.CreateScope();
|
|
var repo = scope.ServiceProvider.GetRequiredService<IRepository<DictionaryCategory>>();
|
|
var list = repo.ReadOnlyTable()
|
|
.Where(o => o.Key == key)
|
|
.SelectMany(o=>o.Items)
|
|
.OrderBy(o=>o.Order)
|
|
.Select(o => new { o.Name, o.Value })
|
|
.ToList();
|
|
return new JsonResult(new SelectList(list, "Value", "Name", selected));
|
|
}
|
|
|
|
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, o.DisplayName })
|
|
.ToList()
|
|
.Select(o=>new { o.Id,Name=o.DisplayName??o.Name})
|
|
.ToList();
|
|
return new JsonResult(new SelectList(list, "Id", "Name", selected));
|
|
}
|
|
}
|
|
}
|