You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
2.2 KiB
55 lines
2.2 KiB
using Application.Domain.Entities;
|
|
using Application.Models;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using Infrastructure.Web.Mvc;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Configuration;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace IoTCenter.Areas.Admin.Controllers
|
|
{
|
|
[Authorize]
|
|
[Area(nameof(Admin))]
|
|
public class DeviceController : CrudController<Device, DeviceSearchMode, EditDeviceModel, EditDeviceModel>
|
|
{
|
|
private readonly IConfiguration _cfg;
|
|
private readonly IRepository<product> _productRepo;
|
|
|
|
public DeviceController(IConfiguration cfg, IRepository<product> productRepo, IRepository<Device> repo) : base(repo)
|
|
{
|
|
this._cfg = cfg;
|
|
this._productRepo = productRepo;
|
|
}
|
|
|
|
public override IActionResult Add()
|
|
{
|
|
var model = new EditDeviceModel
|
|
{
|
|
CategoryNumber = "20",
|
|
InfoNumber = "serialport",
|
|
ConnectId = this._cfg["ConnectId"],
|
|
Number = Guid.NewGuid().ToBase62(),
|
|
NodeNumber = this._cfg["node.number"]
|
|
};
|
|
return View(model);
|
|
}
|
|
|
|
public override void ToEntity(EditDeviceModel model, Device entity)
|
|
{
|
|
if (!this.repo.ReadOnlyTable().Any(o => o.Id == model.Id))
|
|
{
|
|
entity.ProductId = this._productRepo.ReadOnlyTable().First().Id;
|
|
entity.AddorUpdateData("SerialPort", "", DeviceDataType.String, "串口", hidden: true);
|
|
entity.AddorUpdateData("Baud", "9600", DeviceDataType.Int, "波特率", hidden: true);
|
|
entity.AddorUpdateData("Partity", "0", DeviceDataType.Int, "校验位", hidden: true);
|
|
entity.AddorUpdateData("DataBits", "8", DeviceDataType.Int, "数据位", hidden: true);
|
|
entity.AddorUpdateData("StopBits", "1", DeviceDataType.Int, "停止位", hidden: true);
|
|
entity.AddorUpdateData("Buttons", new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("测试按键", "11111111") }.ToJson(), DeviceDataType.SelectList, "按键");
|
|
}
|
|
}
|
|
}
|
|
} |