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.9 KiB
86 lines
3.9 KiB
using Infrastructure.Application;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using Infrastructure.Web.Mvc;
|
|
using 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.IoTDevice).ThenInclude(o => o.IoTGateway)
|
|
.Include(o=>o.IoTDevice).ThenInclude(o=>o.IoTProduct);
|
|
}
|
|
|
|
public override IQueryable<IoTData> Query(PagedListModel<EditIoTDataModel> model, IQueryable<IoTData> query)
|
|
{
|
|
return query
|
|
.WhereIf(model.Query.ProductId.HasValue, o => o.IoTDevice.IoTProductId == model.Query.ProductId.Value)
|
|
.WhereIf(model.Query.IoTGatewayId.HasValue, o => o.IoTDevice.IoTGatewayId == model.Query.IoTGatewayId.Value)
|
|
.WhereIf(model.Query.DeviceId.HasValue, o => o.IoTDeviceId == 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.ValueType.HasValue, o => o.ValueType == model.Query.ValueType.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.IoTDevice.IoTProductId).ThenBy(o => o.IoTDevice.IoTGatewayId).ThenBy(o => o.IoTDeviceId);
|
|
}
|
|
|
|
public override void ToDisplayModel(IoTData entity, EditIoTDataModel model)
|
|
{
|
|
if(entity!=null)
|
|
{
|
|
model.ProductId = entity.IoTDevice.IoTProductId;
|
|
model.IoTGatewayId = entity.IoTDevice.IoTGatewayId;
|
|
}
|
|
if(model.ProductId.HasValue)
|
|
{
|
|
ViewData.Add(model.ProductId, entity.IoTDevice.IoTProduct.Name);
|
|
}
|
|
if(model.DeviceId.HasValue)
|
|
{
|
|
ViewData.Add(model.DeviceId, entity.IoTDevice.Name);
|
|
}
|
|
if(model.IoTGatewayId.HasValue)
|
|
{
|
|
ViewData.Add(model.IoTGatewayId, entity.IoTDevice.IoTGateway.Name);
|
|
}
|
|
}
|
|
|
|
public override void ToEditModel(IoTData entity, EditIoTDataModel model)
|
|
{
|
|
model.IoTGatewayId = entity?.IoTDevice?.IoTGatewayId;
|
|
ViewData.SelectList(o => model.ProductId, () => this._ajax.GetIoTProduct(model.ProductId).SelectList());
|
|
ViewData.SelectList(o => model.IoTGatewayId, () => this._ajax.GetIoTGateway(model.IoTGatewayId).SelectList());
|
|
if (model.IoTGatewayId.HasValue)
|
|
{
|
|
ViewData.SelectList(o => model.DeviceId, () => this._ajax.GetIoTDevice(model.IoTGatewayId.Value, model.DeviceId).SelectList());
|
|
}
|
|
}
|
|
}
|
|
}
|