From 4134f6dd9c2273249fbade65d856aee5e8b9b38d Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Fri, 12 Jul 2019 19:03:57 +0800 Subject: [PATCH] update Former-commit-id: d75e1f0e18cc4ce8fb5e9a150755e109500dc3e3 --- .../Application/Domain/Entities/Data.cs | 2 +- .../Application/Domain/Entities/Device.cs | 2 +- .../Application/Models/EditDataModel.cs | 3 +- .../Application/Models/EditDeviceModel.cs | 12 +--- .../Admin/Controllers/IoT/DeviceController.cs | 60 +------------------ 5 files changed, 7 insertions(+), 72 deletions(-) diff --git a/projects/IoT/IoT.Shared/Application/Domain/Entities/Data.cs b/projects/IoT/IoT.Shared/Application/Domain/Entities/Data.cs index a5a6286d..42271a94 100644 --- a/projects/IoT/IoT.Shared/Application/Domain/Entities/Data.cs +++ b/projects/IoT/IoT.Shared/Application/Domain/Entities/Data.cs @@ -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; } diff --git a/projects/IoT/IoT.Shared/Application/Domain/Entities/Device.cs b/projects/IoT/IoT.Shared/Application/Domain/Entities/Device.cs index aea2c412..9f3c3712 100644 --- a/projects/IoT/IoT.Shared/Application/Domain/Entities/Device.cs +++ b/projects/IoT/IoT.Shared/Application/Domain/Entities/Device.cs @@ -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; } diff --git a/projects/IoT/IoT.Shared/Application/Models/EditDataModel.cs b/projects/IoT/IoT.Shared/Application/Models/EditDataModel.cs index 55310f39..cb76432d 100644 --- a/projects/IoT/IoT.Shared/Application/Models/EditDataModel.cs +++ b/projects/IoT/IoT.Shared/Application/Models/EditDataModel.cs @@ -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))] diff --git a/projects/IoT/IoT.Shared/Application/Models/EditDeviceModel.cs b/projects/IoT/IoT.Shared/Application/Models/EditDeviceModel.cs index 290643d2..9810e2d5 100644 --- a/projects/IoT/IoT.Shared/Application/Models/EditDeviceModel.cs +++ b/projects/IoT/IoT.Shared/Application/Models/EditDeviceModel.cs @@ -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; } } } \ No newline at end of file diff --git a/projects/IoTCenter/Areas/Admin/Controllers/IoT/DeviceController.cs b/projects/IoTCenter/Areas/Admin/Controllers/IoT/DeviceController.cs index cb8ff1f3..2ec51328 100644 --- a/projects/IoTCenter/Areas/Admin/Controllers/IoT/DeviceController.cs +++ b/projects/IoTCenter/Areas/Admin/Controllers/IoT/DeviceController.cs @@ -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 { - private readonly IRepository _nodeRepo; - private readonly IRepository _repo; - private readonly IHubContext _pageHubContext; - private readonly AjaxController _ajax; - private readonly INodeService _nodeService; - - public DeviceController(IRepository nodeRepo, IRepository repo, IHubContext 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 Query(DeviceSearchMode model, IQueryable 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 list) + public DeviceController(IRepository 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(); } } } \ No newline at end of file