|
|
|
@ -1,17 +1,9 @@
|
|
|
|
|
using Application.Domain.Entities;
|
|
|
|
|
using Application.Models;
|
|
|
|
|
using Application.Services;
|
|
|
|
|
using Infrastructure.Data;
|
|
|
|
|
using Infrastructure.Extensions;
|
|
|
|
|
using Infrastructure.Web.Mvc;
|
|
|
|
|
using IoTShared;
|
|
|
|
|
using IoTShared.Controllers;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.SignalR;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace IoTCenter.Areas.Admin.Controllers
|
|
|
|
|
{
|
|
|
|
@ -19,58 +11,8 @@ namespace IoTCenter.Areas.Admin.Controllers
|
|
|
|
|
[Area(nameof(Admin))]
|
|
|
|
|
public class DeviceController : CrudController<Device, DeviceSearchMode, EditDeviceModel, EditDeviceModel>
|
|
|
|
|
{
|
|
|
|
|
private readonly IRepository<Node> _nodeRepo;
|
|
|
|
|
private readonly IRepository<Device> _repo;
|
|
|
|
|
private readonly IHubContext<PageHub> _pageHubContext;
|
|
|
|
|
private readonly AjaxController _ajax;
|
|
|
|
|
private readonly INodeService _nodeService;
|
|
|
|
|
|
|
|
|
|
public DeviceController(IRepository<Node> nodeRepo, IRepository<Device> repo, IHubContext<PageHub> pageHubContext, AjaxController ajax, INodeService nodeService) : base(repo)
|
|
|
|
|
{
|
|
|
|
|
this._repo = repo;
|
|
|
|
|
this._nodeRepo = nodeRepo;
|
|
|
|
|
this._pageHubContext = pageHubContext;
|
|
|
|
|
this._ajax = ajax;
|
|
|
|
|
this._nodeService = nodeService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IQueryable<Device> Query(DeviceSearchMode model, IQueryable<Device> query)
|
|
|
|
|
{
|
|
|
|
|
ViewData.SelectList(o => model.NodeId, () => this._ajax.GetNodeSelectList(model.NodeId));
|
|
|
|
|
return query.WhereIf(model.NodeId.HasValue, o => o.NodeId == model.NodeId.Value)
|
|
|
|
|
.WhereIf(!string.IsNullOrEmpty(model.Keyword), o => o.Name.Contains(model.Keyword));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IActionResult Edit(EditDeviceModel model)
|
|
|
|
|
{
|
|
|
|
|
if (ModelState.IsValid)
|
|
|
|
|
{
|
|
|
|
|
var entity = this._repo.Table().FirstOrDefault(o => o.Id == model.Id);
|
|
|
|
|
var number = this._nodeRepo.ReadOnlyTable().FirstOrDefault(o => o.Id == entity.NodeId).Number;
|
|
|
|
|
this._pageHubContext.Clients.Group(number).SendAsync(nameof(INodeService.EditDevice), model);
|
|
|
|
|
return RedirectTo();
|
|
|
|
|
}
|
|
|
|
|
ModelState.AddModelError("", "服务器出现异常,请稍后重试");
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IActionResult Delete(List<Guid> list)
|
|
|
|
|
public DeviceController(IRepository<Device> repo) : base(repo)
|
|
|
|
|
{
|
|
|
|
|
foreach (var id in list)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var entity = this._repo.Table().FirstOrDefault(o => o.Id == id);
|
|
|
|
|
var number = this._nodeRepo.ReadOnlyTable().FirstOrDefault(o => o.Id == entity.NodeId).Number;
|
|
|
|
|
this._pageHubContext.Clients.Group(number).SendAsync(nameof(INodeService.DeleteDevice), id);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ex.PrintStack();
|
|
|
|
|
return RedirectTo(message: ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return RedirectTo();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|