using Infrastructure.Application; using Microsoft.AspNetCore.Mvc; using Platform.Areas.IoTCenter.Controllers; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; namespace IoT.Shared.Application.Models { [Display(Name = "命令")] public class EditIoTCommandModel : EditModel { [Display(Name = "机构")] [SelectList(nameof(BuildingId),nameof(AjaxController.GetBuilding))] [ReadOnlyForEdit] public Guid? OrganId { get; set; } [Display(Name = "建筑")] [SelectList(nameof(IoTGatewayId), nameof(AjaxController.GetIoTGatewayByBuilding))] [ReadOnlyForEdit] public Guid? BuildingId { get; set; } [SelectList(nameof(DeviceId), nameof(AjaxController.GetIoTDevice))] [Display(Name = "网关")] [Required(ErrorMessage = nameof(RequiredAttribute))] public Guid? IoTGatewayId { get; set; } [SelectList(nameof(ApiId), nameof(AjaxController.GetIoTApiByDevice))] [Display(Name = "设备")] [Required(ErrorMessage = nameof(RequiredAttribute))] public Guid? DeviceId { get; set; } [SelectList] [Display(Name = "Api")] [Required(ErrorMessage = nameof(RequiredAttribute))] public Guid? ApiId { get; set; } [Display(Name = "命令名称")] [MaxLength(24, ErrorMessage = "{0}最大长度为{1}")] public string Name { get; set; } [Display(Name = "序号")] public int Order { get; set; } [Display(Name = "隐藏")] public bool? Disabled { get; set; } [Display(Name = "延迟")] public int? Delay { get; set; } [SkipSearch] [DisplayOnly] [Display(Name = "参数")] public string QueryString { get; set; } [Display(Name = "参数", Order = 50)] [ScaffoldColumn(false)] public List Parameters { get; set; } = new List(); public string GetQueryString() { if (this.Parameters.Any()) { var queryString = string.Empty; foreach (var item in this.Parameters) { queryString += $"&{item.Name}={item.Value}"; } return queryString.TrimStart('&'); } return null; } } }