Former-commit-id: d75e1f0e18cc4ce8fb5e9a150755e109500dc3e3
TangShanKaiPing
wanggang 6 years ago
parent 797d572745
commit 4134f6dd9c

@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations;
namespace Application.Domain.Entities
{
[Display(Name = "数据")]
public class Data : BaseEntity, IDisableRemove
public class Data : BaseEntity, IDisableUpdate
{
[Display(Name = "键")]
public string Key { get; set; }

@ -7,7 +7,7 @@ using System.Linq;
namespace Application.Domain.Entities
{
[Display(Name = "设备")]
public class Device : BaseEntity, IDisableRemove
public class Device : BaseEntity
{
[Display(Name = "网关编号")]
public string GatewayNumber { get; set; }

@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations;
using Application.Domain.Entities;
using Infrastructure.Application;
namespace Application.Models
@ -8,7 +9,7 @@ namespace Application.Models
{
[Display(Name = "类型")]
[Required(ErrorMessage = nameof(RequiredAttribute))]
public string Type { get; set; }
public DeviceDataType Type { get; set; }
[Display(Name = "键")]
[Required(ErrorMessage = nameof(RequiredAttribute))]

@ -1,6 +1,6 @@
using Infrastructure.Application;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Infrastructure.Application;
namespace Application.Models
{
@ -21,16 +21,8 @@ namespace Application.Models
[Required(ErrorMessage = nameof(RequiredAttribute))]
public string Number { get; set; }
[ReadOnly(true)]
[Display(Name = "在线状态")]
public bool IsOnline { get; set; }
[ReadOnly(true)]
[Display(Name = "地址")]
[Required(ErrorMessage = nameof(RequiredAttribute))]
public string BaseUrl { get; set; }
[ReadOnly(true)]
[Required(ErrorMessage = nameof(RequiredAttribute))]
public string ApiPath { get; set; }
}
}

@ -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();
}
}
}
Loading…
Cancel
Save