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/Platform/Areas/IoTCenter/Controllers/IoTDeviceController.cs

77 lines
4.1 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 Platform.Areas.IoTCenter.Controllers;
using System;
using System.Linq;
namespace IoT.Shared.Areas.IoTCenter.Controlls
{
[Authorize]
[ApiController]
[Route("IoTCenter/[controller]/[action]")]
[Area("IoTCenter")]
[ControllerScope(ControllerScopeType.Platform)]
public class IoTDeviceController : IoTSharedController<IoTDevice, EditDeviceModel>
{
private readonly AjaxController _ajax;
public IoTDeviceController(IRepository<IoTDevice> repo, AjaxController ajax, IServiceProvider sp) : base(repo, sp)
{
this._ajax = ajax;
}
public override IQueryable<IoTDevice> Include(IQueryable<IoTDevice> query)
{
return query.Include(o => o.Product)
.Include(o => o.Node).ThenInclude(o=>o.Building).ThenInclude(o=>o.Organ);
}
public override IQueryable<IoTDevice> Query(PagedListModel<EditDeviceModel> model, IQueryable<IoTDevice> query)
{
return query
.WhereIf(model.Query.OrganId.HasValue, o => o.Node.Building.OrganId == model.Query.OrganId.Value)
.WhereIf(model.Query.BuildingId.HasValue, o => o.Node.BuildingId == model.Query.BuildingId.Value)
.WhereIf(model.Query.NodeId.HasValue, o => o.NodeId == model.Query.NodeId.Value)
.WhereIf(model.Query.ProductId.HasValue, o => o.ProductId == model.Query.ProductId.Value)
.WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name))
.WhereIf(!string.IsNullOrEmpty(model.Query.DisplayName), o => o.DisplayName.Contains(model.Query.DisplayName))
.WhereIf(!string.IsNullOrEmpty(model.Query.Gateway), o => o.Gateway.Contains(model.Query.Gateway))
.WhereIf(!string.IsNullOrEmpty(model.Query.Tag), o => o.Tag.Contains(model.Query.Tag))
.WhereIf(!string.IsNullOrEmpty(model.Query.Ip), o => o.Ip.Contains(model.Query.Ip))
.WhereIf(!string.IsNullOrEmpty(model.Query.UserName), o => o.UserName.Contains(model.Query.UserName))
.WhereIf(!string.IsNullOrEmpty(model.Query.Password), o => o.Password.Contains(model.Query.Password))
.WhereIf(!string.IsNullOrEmpty(model.Query.Number), o => o.Number.Contains(model.Query.Number))
.WhereIf(!string.IsNullOrEmpty(model.Query.Icon), o => o.Icon.Contains(model.Query.Icon))
.WhereIf(!string.IsNullOrEmpty(model.Query.ConnectId), o => o.ConnectId.Contains(model.Query.ConnectId))
.WhereIf(model.Query.IsOnline.HasValue, o => o.IsOnline == model.Query.IsOnline.Value)
.WhereIf(model.Query.Disabled.HasValue, o => o.Disabled == model.Query.Disabled.Value);
}
public override void ToDisplayModel(IoTDevice entity, EditDeviceModel model)
{
ViewData.Add(model.NodeId, entity?.Node?.Name);
ViewData.Add(model.ProductId, entity?.Product?.Name);
}
public override void ToEditModel(IoTDevice entity, EditDeviceModel model)
{
ViewData.SelectList(o => model.ProductCategoryId, () => this._ajax.GetIoTProductCategory(model.ProductCategoryId).SelectList());
ViewData.SelectList(o => model.ProductId, () => this._ajax.GetIoTProduct(model.ProductCategoryId).SelectList());
//ViewData.SelectList(o => model.NodeId, () => this._ajax.GetIoTGateway(model.NodeId).SelectList());
//ViewData.SelectList(o => model.ProductId, () => this._ajax.GetIoTProduct(model.ProductId).SelectList());
}
public override string GetNodeNumber(EditDeviceModel model)
{
return this.Repo.ReadOnlyTable().Where(o => o.NodeId == model.NodeId).Select(o => o.Node.Number).FirstOrDefault();
}
}
}