diff --git a/projects/Infrastructure/Web/Mvc/CrudController.cs b/projects/Infrastructure/Web/Mvc/CrudController.cs index bd1e5a72..7f731372 100644 --- a/projects/Infrastructure/Web/Mvc/CrudController.cs +++ b/projects/Infrastructure/Web/Mvc/CrudController.cs @@ -47,6 +47,7 @@ namespace Infrastructure.Web.Mvc .Select(o => { var m = o.To(); + this.EntityToModel(o,m); this.ToDisplayModel(o, m); return m; }) @@ -62,6 +63,7 @@ namespace Infrastructure.Web.Mvc query = this.Include(query); var entity = query.FirstOrDefault(o => o.Id == id); var model = entity.To(); + this.EntityToModel(entity,model); this.ToDisplayModel(entity, model); return Result(model); } @@ -136,6 +138,7 @@ namespace Infrastructure.Web.Mvc query = this.Include(query); var entity = query.FirstOrDefault(o => o.Id == id); var model = entity.To(); + this.EntityToModel(entity,model); this.ToEditModel(entity, model); return Result(model); } @@ -164,6 +167,7 @@ namespace Infrastructure.Web.Mvc ModelState.AddModelError("", ex.Message); } } + this.EntityToModel(entity,model); this.ToEditModel(entity, model); return Result(model); } @@ -256,6 +260,11 @@ namespace Infrastructure.Web.Mvc return query; } + public virtual void EntityToModel(TEntity entity, TEditModel model) + { + + } + [ApiExplorerSettings(IgnoreApi = true)] public virtual void ToEditModel(TEntity entity, TEditModel model) { diff --git a/projects/IoT.Shared/Application/Models/EditIoTApiModel.cs b/projects/IoT.Shared/Application/Models/EditIoTApiModel.cs index ab85c984..50cf253d 100644 --- a/projects/IoT.Shared/Application/Models/EditIoTApiModel.cs +++ b/projects/IoT.Shared/Application/Models/EditIoTApiModel.cs @@ -11,7 +11,7 @@ namespace IoT.Shared.Application.Models [ReadOnlyForEdit] [SelectList] [Required(ErrorMessage = nameof(RequiredAttribute))] - public Guid? ProductId { get; set; } + public Guid? IoTProductId { get; set; } [Display(Name = "名称")] [ReadOnlyForEdit] diff --git a/projects/IoTNode/Areas/IoTCenter/Controllers/IoTApiController.cs b/projects/IoTNode/Areas/IoTCenter/Controllers/IoTApiController.cs index ec33c734..766c9b32 100644 --- a/projects/IoTNode/Areas/IoTCenter/Controllers/IoTApiController.cs +++ b/projects/IoTNode/Areas/IoTCenter/Controllers/IoTApiController.cs @@ -33,9 +33,9 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls public override IQueryable Query(PagedListModel model, IQueryable query) { - ViewData.SelectList(o => model.Query.ProductId, () => this._ajax.GetIoTProduct(model.Query.ProductId).SelectList()); + ViewData.SelectList(o => model.Query.IoTProductId, () => this._ajax.GetIoTProduct(model.Query.IoTProductId).SelectList()); return query - .WhereIf(model.Query.ProductId.HasValue, o => o.IoTProductId == model.Query.ProductId.Value) + .WhereIf(model.Query.IoTProductId.HasValue, o => o.IoTProductId == model.Query.IoTProductId.Value) .WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name)) .WhereIf(!string.IsNullOrEmpty(model.Query.Path), o => o.Path.Contains(model.Query.Path)) .WhereIf(!string.IsNullOrEmpty(model.Query.Command), o => o.Command.Contains(model.Query.Command)) @@ -44,13 +44,13 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls public override void ToDisplayModel(IoTApi entity, EditIoTApiModel model) { - ViewData.Add(model.ProductId, entity?.Product?.Name); + ViewData.Add(model.IoTProductId, entity?.Product?.Name); } public override void ToEditModel(IoTApi entity, EditIoTApiModel model) { this.ToDisplayModel(entity, model); - ViewData.SelectList(o => model.ProductId, () => this._ajax.GetIoTProduct(model.ProductId).SelectList()); + ViewData.SelectList(o => model.IoTProductId, () => this._ajax.GetIoTProduct(model.IoTProductId).SelectList()); } } } diff --git a/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTApiModel.cs b/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTApiModel.cs index 5b01c9bc..cc774ea0 100644 --- a/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTApiModel.cs +++ b/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTApiModel.cs @@ -10,7 +10,7 @@ namespace Platform.Application.Models.IoTCenter { [Display(Name = "分类")] [ReadOnlyForEdit] - [SelectList(nameof(ProductId), nameof(AjaxController.GetIoTProductByCategory))] - public Guid? CategoryId { get; set; } + [SelectList(nameof(IoTProductId), nameof(AjaxController.GetIoTProductByCategory))] + public Guid? IoTProductCategoryId { get; set; } } } diff --git a/projects/Platform/Areas/IoTCenter/Controllers/IoTApiController.cs b/projects/Platform/Areas/IoTCenter/Controllers/IoTApiController.cs index 2717f533..281a503d 100644 --- a/projects/Platform/Areas/IoTCenter/Controllers/IoTApiController.cs +++ b/projects/Platform/Areas/IoTCenter/Controllers/IoTApiController.cs @@ -37,46 +37,49 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls public override IQueryable Query(PagedListModel model, IQueryable query) { - ViewData.SelectList(o => model.Query.ProductId, () => this._ajax.GetIoTProduct(model.Query.ProductId).SelectList()); + ViewData.SelectList(o => model.Query.IoTProductId, () => this._ajax.GetIoTProduct(model.Query.IoTProductId).SelectList()); return query - .WhereIf(model.Query.CategoryId.HasValue, o => o.Product.IoTProductCategoryId == model.Query.CategoryId.Value) - .WhereIf(model.Query.ProductId.HasValue, o => o.IoTProductId == model.Query.ProductId.Value) + .WhereIf(model.Query.IoTProductCategoryId.HasValue, o => o.Product.IoTProductCategoryId == model.Query.IoTProductCategoryId.Value) + .WhereIf(model.Query.IoTProductId.HasValue, o => o.IoTProductId == model.Query.IoTProductId.Value) .WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name)) .WhereIf(!string.IsNullOrEmpty(model.Query.Path), o => o.Path.Contains(model.Query.Path)) .WhereIf(!string.IsNullOrEmpty(model.Query.Command), o => o.Command.Contains(model.Query.Command)) .WhereIf(!string.IsNullOrEmpty(model.Query.Method), o => o.Method.Contains(model.Query.Method)); } + public override void EntityToModel(IoTApi entity, EditPlatformIoTApiModel model) + { + model.IoTProductCategoryId = entity?.Product?.IoTProductCategoryId; + } + public override void ToDisplayModel(IoTApi entity, EditPlatformIoTApiModel model) { - model.CategoryId = entity?.Product?.IoTProductCategoryId; if (entity != null) { - ViewData.Add(model.ProductId.Value, entity.Product.Name); + ViewData.Add(model.IoTProductId.Value, entity.Product?.Name); } - if (model.CategoryId.HasValue) + if (model.IoTProductCategoryId.HasValue) { var name = this._categoryRepo.ReadOnlyTable() .Where(o => o.ParentId != null) .Where(o => o.Left <= entity.Product.IoTProductCategory.Left && o.Right >= entity.Product.IoTProductCategory.Right) .ToList() .ToTree() - .FirstOrDefault(o => o.Id == model.CategoryId.Value)?.GetDisplayName(); - ViewData.Add(model.CategoryId.Value, name); + .FirstOrDefault(o => o.Id == model.IoTProductCategoryId.Value)?.GetDisplayName(); + ViewData.Add(model.IoTProductCategoryId.Value, name); } } public override void ToEditModel(IoTApi entity, EditPlatformIoTApiModel model) { - model.CategoryId = entity?.Product?.IoTProductCategoryId; - ViewData.SelectList(o => model.CategoryId, () => this._ajax.GetIoTProductCategory(model.CategoryId).SelectList()); - if (model.CategoryId.HasValue) + ViewData.SelectList(o => model.IoTProductCategoryId, () => this._ajax.GetIoTProductCategory(model.IoTProductCategoryId).SelectList()); + if (model.IoTProductCategoryId.HasValue) { - ViewData.SelectList(o => model.ProductId, () => this._ajax.GetIoTProductByCategory(model.CategoryId.Value, model.ProductId).SelectList()); + ViewData.SelectList(o => model.IoTProductId, () => this._ajax.GetIoTProductByCategory(model.IoTProductCategoryId.Value, model.IoTProductId).SelectList()); } else { - ViewData.Add(model.ProductId, entity?.Product?.Name); + ViewData.Add(model.IoTProductId, entity?.Product?.Name); } } } diff --git a/projects/Platform/Areas/IoTCenter/Controllers/IoTCommandController.cs b/projects/Platform/Areas/IoTCenter/Controllers/IoTCommandController.cs index e6dfba03..abc35373 100644 --- a/projects/Platform/Areas/IoTCenter/Controllers/IoTCommandController.cs +++ b/projects/Platform/Areas/IoTCenter/Controllers/IoTCommandController.cs @@ -106,14 +106,15 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls return PartialView("_Code", model); } + public override void EntityToModel(IoTCommand entity, EditIoTCommandModel model) + { + model.IoTGatewayId = entity.IoTDevice?.IoTGatewayId; + model.BuildingId = entity.IoTDevice?.IoTGateway?.BuildingId; + model.OrganId = entity.IoTDevice?.IoTGateway?.Building?.OrganId; + } + public override void ToDisplayModel(IoTCommand entity, EditIoTCommandModel model) { - if (entity != null) - { - model.IoTGatewayId = entity.IoTDevice?.IoTGatewayId; - model.BuildingId = entity.IoTDevice?.IoTGateway?.BuildingId; - model.OrganId = entity.IoTDevice?.IoTGateway?.Building?.OrganId; - } if (model.BuildingId.HasValue) { var name = this._buildingRepo.ReadOnlyTable() @@ -150,12 +151,6 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls public override void ToEditModel(IoTCommand entity, EditIoTCommandModel model) { - if (entity != null) - { - model.IoTGatewayId = entity.IoTDevice?.IoTGatewayId; - model.BuildingId = entity.IoTDevice?.IoTGateway?.BuildingId; - model.OrganId = entity.IoTDevice?.IoTGateway?.Building?.OrganId; - } ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList()); ViewData.SelectList(o => model.BuildingId, () => this._ajax.GetBuilding(model.OrganId.Value, model.BuildingId).SelectList(), model.OrganId.HasValue); ViewData.SelectList(o => model.IoTGatewayId, () => this._ajax.GetIoTGatewayByBuilding(model.BuildingId.Value, model.IoTGatewayId).SelectList(), model.BuildingId.HasValue); diff --git a/projects/Platform/Areas/IoTCenter/Controllers/IoTDataController.cs b/projects/Platform/Areas/IoTCenter/Controllers/IoTDataController.cs index 68136f3d..28f3d11c 100644 --- a/projects/Platform/Areas/IoTCenter/Controllers/IoTDataController.cs +++ b/projects/Platform/Areas/IoTCenter/Controllers/IoTDataController.cs @@ -74,16 +74,17 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls .OrderBy(o => o.IoTDevice.IoTProductId).ThenBy(o => o.IoTDevice.IoTGatewayId).ThenBy(o => o.IoTDeviceId); } + public override void EntityToModel(IoTData entity, EditPlatformIoTDataModel model) + { + model.ProductId = entity.IoTDevice?.IoTProductId; + model.CategoryId = entity.IoTDevice?.IoTProduct?.IoTProductCategoryId; + model.IoTGatewayId = entity.IoTDevice?.IoTGatewayId; + model.BuildingId = entity.IoTDevice?.IoTGateway?.BuildingId; + model.OrganId = entity.IoTDevice?.IoTGateway?.Building?.OrganId; + } + public override void ToDisplayModel(IoTData entity, EditPlatformIoTDataModel model) { - if (entity != null) - { - model.ProductId = entity.IoTDevice.IoTProductId; - model.CategoryId = entity.IoTDevice.IoTProduct.IoTProductCategoryId; - model.IoTGatewayId = entity.IoTDevice.IoTGatewayId; - model.BuildingId = entity.IoTDevice.IoTGateway.BuildingId; - model.OrganId = entity.IoTDevice.IoTGateway.Building.OrganId; - } if (model.BuildingId.HasValue) { var name = this._buildingRepo.ReadOnlyTable() @@ -130,12 +131,6 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls public override void ToEditModel(IoTData entity, EditPlatformIoTDataModel model) { - if (entity != null) - { - model.BuildingId = entity.IoTDevice.IoTGateway.BuildingId; - model.OrganId = entity.IoTDevice.IoTGateway.Building.OrganId; - model.CategoryId = entity.IoTDevice.IoTProduct.IoTProductCategoryId; - } ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList()); ViewData.SelectList(o => model.BuildingId, () => this._ajax.GetBuilding(model.OrganId.Value, model.BuildingId).SelectList(), model.OrganId.HasValue); ViewData.SelectList(o => model.IoTGatewayId, () => this._ajax.GetIoTGatewayByBuilding(model.BuildingId.Value, model.IoTGatewayId).SelectList(), model.BuildingId.HasValue); diff --git a/projects/Platform/Areas/IoTCenter/Controllers/IoTDeviceController.cs b/projects/Platform/Areas/IoTCenter/Controllers/IoTDeviceController.cs index 4fc5fafc..c3038b07 100644 --- a/projects/Platform/Areas/IoTCenter/Controllers/IoTDeviceController.cs +++ b/projects/Platform/Areas/IoTCenter/Controllers/IoTDeviceController.cs @@ -69,14 +69,15 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls .WhereIf(model.Query.Disabled.HasValue, o => o.Disabled == model.Query.Disabled.Value); } + public override void EntityToModel(IoTDevice entity, EditPlatformIoTDeviceModel model) + { + model.BuildingId = entity.IoTGateway?.BuildingId; + model.OrganId = entity.IoTGateway?.Building?.OrganId; + model.CategoryId = entity.IoTProduct?.IoTProductCategoryId; + } + public override void ToDisplayModel(IoTDevice entity, EditPlatformIoTDeviceModel model) { - if (entity != null) - { - model.BuildingId = entity.IoTGateway.BuildingId; - model.OrganId = entity.IoTGateway.Building.OrganId; - model.CategoryId = entity.IoTProduct.IoTProductCategoryId; - } if (model.BuildingId.HasValue) { var name = this._buildingRepo.ReadOnlyTable() @@ -119,12 +120,6 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls public override void ToEditModel(IoTDevice entity, EditPlatformIoTDeviceModel model) { - if (entity != null) - { - model.BuildingId = entity.IoTGateway.BuildingId; - model.OrganId = entity.IoTGateway.Building.OrganId; - model.CategoryId = entity.IoTProduct.IoTProductCategoryId; - } ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList()); ViewData.SelectList(o => model.BuildingId, () => this._ajax.GetBuilding(model.OrganId.Value, model.BuildingId).SelectList(), model.OrganId.HasValue); ViewData.SelectList(o => model.CategoryId, () => this._ajax.GetIoTProductCategory(model.CategoryId).SelectList()); diff --git a/projects/Platform/Areas/IoTCenter/Controllers/IoTGatewayController.cs b/projects/Platform/Areas/IoTCenter/Controllers/IoTGatewayController.cs index dc6bbb9e..e3ae9218 100644 --- a/projects/Platform/Areas/IoTCenter/Controllers/IoTGatewayController.cs +++ b/projects/Platform/Areas/IoTCenter/Controllers/IoTGatewayController.cs @@ -54,12 +54,13 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls .WhereIf(model.Query.Hidden.HasValue, o => o.Hidden == model.Query.Hidden.Value); } + public override void EntityToModel(IoTGateway entity, EditPlatformIoTGatewayModel model) + { + model.OrganId = entity?.Building?.OrganId; + } + public override void ToDisplayModel(IoTGateway entity, EditPlatformIoTGatewayModel model) { - if(entity!=null) - { - model.OrganId = entity?.Building?.OrganId; - } if (model.BuildingId.HasValue) { var name = this._buildingRepo.ReadOnlyTable() @@ -84,10 +85,6 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls public override void ToEditModel(IoTGateway entity, EditPlatformIoTGatewayModel model) { - if(entity!=null) - { - model.OrganId = entity?.Building?.OrganId; - } ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList()); ViewData.SelectList(o => model.BuildingId, () => this._ajax.GetBuilding(model.OrganId.Value, model.BuildingId).SelectList(),model.OrganId.HasValue); } diff --git a/projects/Platform/Areas/IoTCenter/Controllers/IoTParameterController.cs b/projects/Platform/Areas/IoTCenter/Controllers/IoTParameterController.cs index 4be5236d..7ffdeef4 100644 --- a/projects/Platform/Areas/IoTCenter/Controllers/IoTParameterController.cs +++ b/projects/Platform/Areas/IoTCenter/Controllers/IoTParameterController.cs @@ -48,13 +48,15 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls .WhereIf(!string.IsNullOrEmpty(model.Query.Minimum), o => o.Minimum == model.Query.Minimum) .WhereIf(!string.IsNullOrEmpty(model.Query.Maxinum), o => o.Maxinum == model.Query.Maxinum); } - + public override void EntityToModel(IoTParameter entity, EditPlatformIoTParameterModel model) + { + model.ProductId = entity.IoTApi.IoTProductId; + model.CategoryId = entity.IoTApi.Product.IoTProductCategoryId; + } public override void ToDisplayModel(IoTParameter entity, EditPlatformIoTParameterModel model) { if (entity != null) { - model.ProductId = entity.IoTApi.IoTProductId; - model.CategoryId = entity.IoTApi.Product.IoTProductCategoryId; ViewData.Add(model.ApiId, entity.IoTApi.Name); } if (model.CategoryId.HasValue) @@ -75,11 +77,6 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls public override void ToEditModel(IoTParameter entity, EditPlatformIoTParameterModel model) { - if(entity!=null) - { - model.ProductId = entity.IoTApi.IoTProductId; - model.CategoryId = entity.IoTApi.Product.IoTProductCategoryId; - } ViewData.SelectList(o => model.CategoryId, () => this._ajax.GetIoTProductCategory(model.CategoryId).SelectList()); ViewData.SelectList(o => model.ProductId, () => this._ajax.GetIoTProductByCategory(model.CategoryId.Value, model.ProductId).SelectList(), model.CategoryId.HasValue); ViewData.SelectList(o => model.ApiId, () => this._ajax.GetIoTApi(model.ProductId.Value, model.ApiId).SelectList(), model.ProductId.HasValue); diff --git a/projects/Platform/Areas/IoTCenter/Controllers/IoTSceneController.cs b/projects/Platform/Areas/IoTCenter/Controllers/IoTSceneController.cs index 0432feb7..6a75fe03 100644 --- a/projects/Platform/Areas/IoTCenter/Controllers/IoTSceneController.cs +++ b/projects/Platform/Areas/IoTCenter/Controllers/IoTSceneController.cs @@ -50,12 +50,13 @@ namespace Platform.Areas.IoTCenter.Controllers .OrderBy(o => o.DisplayOrder); } + public override void EntityToModel(IoTScene entity, EditIoTSceneModel model) + { + model.OrganId = entity.Building.OrganId; + } + public override void ToDisplayModel(IoTScene entity, EditIoTSceneModel model) { - if(entity!=null) - { - model.OrganId = entity.Building.OrganId; - } if (model.BuildingId.HasValue) { var name = this._buildingRepo.ReadOnlyTable() @@ -80,10 +81,6 @@ namespace Platform.Areas.IoTCenter.Controllers public override void ToEditModel(IoTScene entity, EditIoTSceneModel model) { - if (entity != null) - { - model.OrganId = entity.Building.OrganId; - } ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList()); ViewData.SelectList(o => model.BuildingId, () => this._ajax.GetBuilding(model.OrganId.Value, model.BuildingId).SelectList(), model.OrganId.HasValue); } diff --git a/projects/Platform/Areas/IoTCenter/Controllers/IoTSceneIoTCommandController.cs b/projects/Platform/Areas/IoTCenter/Controllers/IoTSceneIoTCommandController.cs index acc1f578..01feca14 100644 --- a/projects/Platform/Areas/IoTCenter/Controllers/IoTSceneIoTCommandController.cs +++ b/projects/Platform/Areas/IoTCenter/Controllers/IoTSceneIoTCommandController.cs @@ -54,14 +54,16 @@ namespace Platform.Areas.IoTCenter.Controllers .WhereIf(model.Query.IoTCommandId.HasValue, o => o.IoTCommandId == model.Query.IoTCommandId.Value) .OrderBy(o => o.IoTSceneId); } + + public override void EntityToModel(IoTSceneIoTCommand entity, EditIoTSceneIoTCommandModel model) + { + model.OrganId = entity.IoTScene?.Building?.OrganId; + model.IoTSceneBuildingId = entity.IoTScene?.BuildingId; + model.DeviceBuildingId = entity.IoTCommand?.IoTDevice?.IoTGateway?.BuildingId; + } + public override void ToDisplayModel(IoTSceneIoTCommand entity, EditIoTSceneIoTCommandModel model) { - if(entity!=null) - { - model.OrganId = entity.IoTScene?.Building?.OrganId; - model.IoTSceneBuildingId = entity.IoTScene?.BuildingId; - model.DeviceBuildingId = entity.IoTCommand?.IoTDevice?.IoTGateway?.BuildingId; - } if (model.OrganId.HasValue) { var name = this._organRepo.ReadOnlyTable() @@ -100,12 +102,6 @@ namespace Platform.Areas.IoTCenter.Controllers } public override void ToEditModel(IoTSceneIoTCommand entity, EditIoTSceneIoTCommandModel model) { - if (entity != null) - { - model.OrganId = entity.IoTScene?.Building?.OrganId; - model.IoTSceneBuildingId = entity.IoTScene?.BuildingId; - model.DeviceBuildingId = entity.IoTCommand?.IoTDevice?.IoTGateway?.BuildingId; - } ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList()); ViewData.SelectList(o => model.IoTSceneId, () => this._ajax.GetIoTScene(model.IoTSceneBuildingId.Value, model.IoTSceneId).SelectList(), model.IoTSceneBuildingId.HasValue); ViewData.SelectList(o => model.IoTSceneBuildingId, () => this._ajax.GetBuilding(model.OrganId.Value, model.IoTSceneBuildingId).SelectList(), model.OrganId.HasValue); diff --git a/projects/Platform/Areas/IoTCenter/Controllers/IoTTiggerController.cs b/projects/Platform/Areas/IoTCenter/Controllers/IoTTiggerController.cs index 8b144187..2c954b4b 100644 --- a/projects/Platform/Areas/IoTCenter/Controllers/IoTTiggerController.cs +++ b/projects/Platform/Areas/IoTCenter/Controllers/IoTTiggerController.cs @@ -61,16 +61,18 @@ namespace Platform.Areas.IoTCenter.Controllers .WhereIf(model.Query.Disabled.HasValue, o => o.Disabled == model.Query.Disabled.Value) .OrderBy(o => o.IoTSceneId); } + + public override void EntityToModel(IoTTigger entity, EditIoTTiggerModel model) + { + model.OrganId = entity.IoTScene?.Building?.OrganId; + model.IoTSceneBuildingId = entity.IoTScene?.BuildingId; + model.IoTDeviceBuildingId = entity.IoTData?.IoTDevice?.IoTGateway?.BuildingId; + model.IoTDeviceId = entity.IoTData?.IoTDeviceId; + model.IoTGatewayId = entity.IoTData?.IoTDevice?.IoTGatewayId; + } + public override void ToDisplayModel(IoTTigger entity, EditIoTTiggerModel model) { - if (entity != null) - { - model.OrganId = entity.IoTScene?.Building?.OrganId; - model.IoTSceneBuildingId = entity.IoTScene?.BuildingId; - model.IoTDeviceBuildingId = entity.IoTData?.IoTDevice?.IoTGateway?.BuildingId; - model.IoTDeviceId = entity.IoTData?.IoTDeviceId; - model.IoTGatewayId = entity.IoTData?.IoTDevice?.IoTGatewayId; - } if (model.OrganId.HasValue) { var name = this._organRepo.ReadOnlyTable() @@ -111,22 +113,12 @@ namespace Platform.Areas.IoTCenter.Controllers public override void ToEditModel(IoTTigger entity, EditIoTTiggerModel model) { - if (entity != null) - { - model.OrganId = entity.IoTScene?.Building?.OrganId; - model.IoTSceneBuildingId = entity.IoTScene?.BuildingId; - model.IoTDeviceBuildingId = entity.IoTData?.IoTDevice?.IoTGateway?.BuildingId; - model.IoTDeviceId = entity.IoTData?.IoTDeviceId; - model.IoTGatewayId = entity.IoTData?.IoTDevice?.IoTGatewayId; - } ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList()); ViewData.SelectList(o => model.IoTSceneBuildingId, () => this._ajax.GetBuilding(model.OrganId.Value, model.IoTSceneBuildingId).SelectList(), model.OrganId.HasValue); ViewData.SelectList(o => model.IoTSceneId, () => this._ajax.GetIoTScene(model.IoTSceneBuildingId.Value, model.IoTSceneId).SelectList(), model.IoTSceneBuildingId.HasValue); ViewData.SelectList(o => model.IoTDeviceBuildingId, () => this._ajax.GetBuildingByScene(model.IoTSceneId.Value, model.IoTDeviceBuildingId).SelectList(), model.IoTSceneId.HasValue); ViewData.SelectList(o => model.IoTGatewayId, () => this._ajax.GetIoTGatewayByBuilding(model.IoTDeviceBuildingId.Value, model.IoTGatewayId).SelectList(), model.IoTDeviceBuildingId.HasValue); ViewData.SelectList(o => model.IoTDeviceId, () => this._ajax.GetIoTDevice(model.IoTGatewayId.Value, model.IoTDeviceId).SelectList(), model.IoTGatewayId.HasValue); - ViewData.SelectList(o => model.IoTDataId, () => this._ajax.GetIoTData(model.IoTDeviceId.Value, model.IoTDataId).SelectList(), model.IoTDeviceId.HasValue); - } } } diff --git a/projects/Platform/Areas/IoTCenter/Controllers/IoTTimerController.cs b/projects/Platform/Areas/IoTCenter/Controllers/IoTTimerController.cs index 8ff64b33..118b8e4d 100644 --- a/projects/Platform/Areas/IoTCenter/Controllers/IoTTimerController.cs +++ b/projects/Platform/Areas/IoTCenter/Controllers/IoTTimerController.cs @@ -50,13 +50,14 @@ namespace Platform.Areas.IoTCenter.Controllers return query.Include(o => o.IoTScene).ThenInclude(o => o.Building).ThenInclude(o => o.Organ); } + public override void EntityToModel(IoTTimer entity, EditIoTTimerModel model) + { + model.BuildingId = entity.IoTScene?.BuildingId; + model.OrganId = entity.IoTScene?.Building?.OrganId; + } + public override void ToDisplayModel(IoTTimer entity, EditIoTTimerModel model) { - if (entity != null) - { - model.BuildingId = entity.IoTScene?.BuildingId; - model.OrganId = entity.IoTScene?.Building?.OrganId; - } if (model.BuildingId.HasValue) { var name = this._buildingRepo.ReadOnlyTable() @@ -82,11 +83,6 @@ namespace Platform.Areas.IoTCenter.Controllers public override void ToEditModel(IoTTimer entity, EditIoTTimerModel model) { - if (entity != null) - { - model.BuildingId = entity.IoTScene?.BuildingId; - model.OrganId = entity.IoTScene?.Building?.OrganId; - } ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList()); ViewData.SelectList(o => model.BuildingId, () => this._ajax.GetBuilding(model.OrganId.Value, model.BuildingId).SelectList(), model.OrganId.HasValue); ViewData.SelectList(o => model.IoTSceneId, () => this._ajax.GetIoTScene(model.BuildingId.Value, model.IoTSceneId).SelectList(), model.BuildingId.HasValue); diff --git a/projects/Platform/Startup.cs b/projects/Platform/Startup.cs index 126a1fb3..54e8e165 100644 --- a/projects/Platform/Startup.cs +++ b/projects/Platform/Startup.cs @@ -1,8 +1,7 @@ using Hangfire; -using Hangfire.Dashboard.BasicAuthorization; +using Hangfire.Dashboard; using Hangfire.MySql; using Hangfire.Storage.SQLite; -using Infrastructure.Data; using Infrastructure.Email; using Infrastructure.Sms; using Infrastructure.UI; @@ -21,8 +20,6 @@ using System; using System.Collections.Generic; using System.Transactions; using UoN.ExpressiveAnnotations.NetCore.DependencyInjection; -using Hangfire.Annotations; -using Hangfire.Dashboard; namespace Platform {