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.
86 lines
3.8 KiB
86 lines
3.8 KiB
using Infrastructure.Application;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using Infrastructure.Web.Mvc;
|
|
using IoT.Shared.Application.Domain.Entities;
|
|
using IoT.Shared.Application.Models;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using System.Linq;
|
|
|
|
namespace IoT.Shared.Areas.IoTCenter.Controlls
|
|
{
|
|
[Authorize]
|
|
[ApiController]
|
|
[Route("IoTCenter/[controller]/[action]")]
|
|
[Area("IoTCenter")]
|
|
[ControllerScope(ControllerScopeType.Platform)]
|
|
public class IoTDataController : CrudController<IoTData, EditIoTDataModel>
|
|
{
|
|
private readonly AjaxBaseController _ajax;
|
|
|
|
public IoTDataController(IRepository<IoTData> repo,
|
|
AjaxBaseController ajax) : base(repo)
|
|
{
|
|
this._ajax = ajax;
|
|
}
|
|
|
|
public override IQueryable<IoTData> Include(IQueryable<IoTData> query)
|
|
{
|
|
return query.Include(o => o.Device).ThenInclude(o => o.Node)
|
|
.Include(o=>o.Device).ThenInclude(o=>o.Product);
|
|
}
|
|
|
|
public override IQueryable<IoTData> Query(PagedListModel<EditIoTDataModel> model, IQueryable<IoTData> query)
|
|
{
|
|
return query
|
|
.WhereIf(model.Query.ProductId.HasValue, o => o.Device.ProductId == model.Query.ProductId.Value)
|
|
.WhereIf(model.Query.NodeId.HasValue, o => o.Device.NodeId == model.Query.NodeId.Value)
|
|
.WhereIf(model.Query.DeviceId.HasValue, o => o.DeviceId == model.Query.DeviceId.Value)
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name))
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Key), o => o.Key.Contains(model.Query.Key))
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Value), o => o.Value.Contains(model.Query.Value))
|
|
.WhereIf(model.Query.Type.HasValue, o => o.Type == model.Query.Type.Value)
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Unit), o => o.Unit.Contains(model.Query.Unit))
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Description), o => o.Description.Contains(model.Query.Description))
|
|
.WhereIf(model.Query.Timestamp.HasValue, o => o.Timestamp == model.Query.Timestamp.Value)
|
|
.WhereIf(model.Query.Hidden.HasValue, o => o.Hidden == model.Query.Hidden.Value)
|
|
.OrderBy(o => o.Device.ProductId).ThenBy(o => o.Device.NodeId).ThenBy(o => o.DeviceId);
|
|
}
|
|
|
|
public override void ToDisplayModel(IoTData entity, EditIoTDataModel model)
|
|
{
|
|
if(entity!=null)
|
|
{
|
|
model.ProductId = entity.Device.ProductId;
|
|
model.NodeId = entity.Device.NodeId;
|
|
}
|
|
if(model.ProductId.HasValue)
|
|
{
|
|
ViewData.Add(model.ProductId, entity.Device.Product.Name);
|
|
}
|
|
if(model.DeviceId.HasValue)
|
|
{
|
|
ViewData.Add(model.DeviceId, entity.Device.Name);
|
|
}
|
|
if(model.NodeId.HasValue)
|
|
{
|
|
ViewData.Add(model.NodeId, entity.Device.Node.Name);
|
|
}
|
|
}
|
|
|
|
public override void ToEditModel(IoTData entity, EditIoTDataModel model)
|
|
{
|
|
model.NodeId = entity?.Device?.NodeId;
|
|
ViewData.SelectList(o => model.ProductId, () => this._ajax.GetIoTProduct(model.ProductId).SelectList());
|
|
ViewData.SelectList(o => model.NodeId, () => this._ajax.GetIoTGateway(model.NodeId).SelectList());
|
|
if (model.NodeId.HasValue)
|
|
{
|
|
ViewData.SelectList(o => model.DeviceId, () => this._ajax.GetIoTDevice(model.NodeId.Value, model.DeviceId).SelectList());
|
|
}
|
|
}
|
|
}
|
|
}
|