public ResponseSerializer Put(int id, [FromBody] DeviceSerializer deviceSerializer) { return(new ResponseSerializer( 200, "success", this._deviceBus.UpdateDevice(id, deviceSerializer))); }
public DeviceSerializer GetDeviceById(int id) { DeviceModel device = this._deviceDao.GetById(id); DeviceSerializer result = new DeviceSerializer(device); return(result); }
public ResponseSerializer Post([FromBody] DeviceSerializer deviceSerializer) { return(new ResponseSerializer( 200, "success", this._deviceBus.CreateNewDevice(deviceSerializer))); }
/* * 上传设备图片 */ public String UploadPicture(PictureUploadSerializer data) { try{ DeviceSerializer device = this.GetDeviceByDeviceId(data.deviceId); device.base64Image = data.picture; this.UpdateDevice(device.id, device); return("图片上传成功"); } catch (Exception ex) { return(ex.Message); } }
/* * 获取所有设备,带分页功能 * * 输入: * 搜索类型 * 页码 * 排序列 * 升序或降序 * 城市 * 工厂 * 车间 * * 输出: * 设备列表 */ public List <DeviceSerializer> GetAllDevices(String searchType, int page, String sortColumn, String order, String city, String factory, String workshop) { int offset = (page - 1) * 12; int limit = 12; List <DeviceModel> devices = this._deviceDao.Get(searchType, offset, limit, sortColumn, order, city, factory, workshop); List <DeviceSerializer> result = new List <DeviceSerializer>(); foreach (DeviceModel device in devices) { DeviceSerializer d = new DeviceSerializer(device); List <String> tags = this._deviceDao.GetDeviceTag(device.Id); d.tags = tags; result.Add(d); } return(result); }
public String CreateNewDevice(DeviceSerializer deviceSerializer) { DeviceModel deviceModel = new DeviceModel(); deviceModel.HardwareDeviceId = deviceSerializer.hardwareDeviceID; deviceModel.DeviceName = deviceSerializer.deviceName; deviceModel.City = deviceSerializer.city; deviceModel.Factory = deviceSerializer.factory; deviceModel.Workshop = deviceSerializer.workshop; deviceModel.DeviceState = deviceSerializer.deviceState; deviceModel.ImageUrl = deviceSerializer.imageUrl; deviceModel.GatewayId = deviceSerializer.gatewayId; deviceModel.Mac = deviceSerializer.mac; deviceModel.DeviceType = deviceSerializer.deviceType; deviceModel.Remark = deviceSerializer.remark; return(this._deviceDao.Create(deviceModel)); }
/* * 获取设备图片 */ public String GetPicture(String deviceId) { try { DeviceSerializer device = this.GetDeviceByDeviceId(deviceId); FileInfo file = new FileInfo(device.pictureRoute); var stream = file.OpenRead(); byte[] buffer = new byte[file.Length]; stream.Read(buffer, 0, Convert.ToInt32(file.Length)); stream.Close(); return(Convert.ToBase64String(buffer)); } catch (Exception e) { Console.WriteLine(e); throw; } }
/* * 更新特定ID(数据库ID)设备 */ public String UpdateDevice(int id, DeviceSerializer deviceSerializer) { DeviceModel deviceModel = new DeviceModel(); deviceModel.Id = id; deviceModel.HardwareDeviceId = deviceSerializer.hardwareDeviceID; deviceModel.DeviceName = deviceSerializer.deviceName; deviceModel.City = deviceSerializer.city; deviceModel.Factory = deviceSerializer.factory; deviceModel.Workshop = deviceSerializer.workshop; deviceModel.DeviceState = deviceSerializer.deviceState; deviceModel.ImageUrl = deviceSerializer.imageUrl; deviceModel.GatewayId = deviceSerializer.gatewayId; deviceModel.Mac = deviceSerializer.mac; deviceModel.DeviceType = deviceSerializer.deviceType; deviceModel.Remark = deviceSerializer.remark; deviceModel.PictureRoute = deviceSerializer.pictureRoute; deviceModel.IsOnline = deviceSerializer.isOnline; deviceModel.Base64Image = deviceSerializer.base64Image; deviceModel.totalAlarmInfo = deviceSerializer.totalAlarmInfo; return(this._deviceDao.Update(id, deviceModel)); }