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

66 lines
3.2 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 System;
using System.Linq;
namespace IoT.Shared.Areas.IoTCenter.Controlls
{
[Authorize]
[ApiController]
[Route("IoTCenter/[controller]/[action]")]
[Area("IoTCenter")]
[ControllerScope(ControllerScopeType.Platform)]
public class IoTDeviceController : CrudController<IoTDevice, EditIoTDeviceModel>
{
private readonly AjaxBaseController _ajax;
public IoTDeviceController(IRepository<IoTDevice> repo, AjaxBaseController ajax) : base(repo)
{
this._ajax = ajax;
}
public override IQueryable<IoTDevice> Include(IQueryable<IoTDevice> query)
{
return query.Include(o => o.Product).Include(o => o.Node);
}
public override IQueryable<IoTDevice> Query(PagedListModel<EditIoTDeviceModel> model, IQueryable<IoTDevice> query)
{
return query
.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, EditIoTDeviceModel model)
{
ViewData.Add(model.NodeId, entity?.Node?.Name);
ViewData.Add(model.ProductId, entity?.Product?.Name);
}
public override void ToEditModel(IoTDevice entity, EditIoTDeviceModel model)
{
ViewData.SelectList(o => model.NodeId, () => this._ajax.GetIoTGateway(model.NodeId).SelectList());
ViewData.SelectList(o => model.ProductId, () => this._ajax.GetIoTProduct(model.ProductId).SelectList());
}
}
}