/// <summary> /// 新增操作信息 /// </summary> /// <param name="coordinator"></param> /// <returns></returns> public static OperationResult Insert(Message message) { try { ES_DB db = new ES_DB(); db.MessageSet.Add(message); db.SaveChanges(); return(new OperationResult(OperationResultType.Success)); } catch (Exception err) { return(new OperationResult(OperationResultType.Error, err.Message)); } }
/// <summary> /// 新增传感器数据 /// </summary> /// <param name="sensorData"></param> /// <returns></returns> public static OperationResult Insert(SensorData sensorData) { try { ES_DB db = new ES_DB(); db.SensorData.Add(sensorData); db.SaveChanges(); return(new OperationResult(OperationResultType.Success)); } catch (Exception err) { return(new OperationResult(OperationResultType.Error, err.Message)); } }
/// <summary> /// 删除传感器数据 /// </summary> /// <param name="sensorData"></param> /// <returns></returns> public static OperationResult Delete(SensorData sensorData) { try { ES_DB db = new ES_DB(); SensorData sensorCore = db.SensorData.Find(sensorData.ID); db.SensorData.Remove(sensorCore); db.SaveChanges(); return(new OperationResult(OperationResultType.Success)); } catch (Exception err) { return(new OperationResult(OperationResultType.Error, err.Message)); } }
/// <summary> /// 删除操作信息 /// </summary> /// <param name="coordinator"></param> /// <returns></returns> public static OperationResult Delete(Message message) { try { ES_DB db = new ES_DB(); //找到集合中对应实体类 Message messageCore = db.MessageSet.Find(message.Id); db.MessageSet.Remove(messageCore); db.SaveChanges(); return(new OperationResult(OperationResultType.Success)); } catch (Exception err) { return(new OperationResult(OperationResultType.Error, err.Message)); } }
/// <summary> /// 新增传感器 /// </summary> /// <param name="sensor"></param> /// <returns></returns> public static OperationResult Insert(Sensor sensor) { try { ES_DB db = new ES_DB(); if (db.Sensor.Count(p => p.Name == sensor.Name) > 0) { return(new OperationResult(OperationResultType.ValidError, "已存在此名称的传感器!")); } db.Sensor.Add(sensor); db.SaveChanges(); return(new OperationResult(OperationResultType.Success)); } catch (Exception err) { return(new OperationResult(OperationResultType.Error, err.Message)); } }
/// <summary> /// 删除协调器 /// </summary> /// <param name="coordinator"></param> /// <returns></returns> public static OperationResult Delete(Coordinator coordinator) { try { ES_DB db = new ES_DB(); //找到集合中对应实体类 Coordinator coorCore = db.Coordinator.Find(coordinator.ID); if (coorCore.Sensor.Count > 0) { return(new OperationResult(OperationResultType.ValidError, "此设备下有传感器!不允许删除!")); } db.Coordinator.Remove(coorCore); db.SaveChanges(); return(new OperationResult(OperationResultType.Success)); } catch (Exception err) { return(new OperationResult(OperationResultType.Error, err.Message)); } }
/// <summary> /// 删除传感器 /// </summary> /// <param name="sensor"></param> /// <returns></returns> public static OperationResult Delete(Sensor sensor) { try { ES_DB db = new ES_DB(); Sensor sensorCore = db.Sensor.Find(sensor.ID); if (sensorCore.SensorData.Count > 0) { return(new OperationResult(OperationResultType.ValidError, "传感器有数据无法删除!")); } db.Sensor.Remove(sensorCore); db.SaveChanges(); return(new OperationResult(OperationResultType.Success)); } catch (Exception err) { return(new OperationResult(OperationResultType.Error, err.Message)); } }
/// <summary> /// 编辑传感器 /// </summary> /// <param name="sensor"></param> /// <returns></returns> public static OperationResult Update(Sensor sensor) { try { ES_DB db = new ES_DB(); Sensor sensorCore = db.Sensor.First(p => p.ID == sensor.ID); if (sensorCore.Name != sensor.Name) { if (db.Sensor.Count(p => p.Name == sensor.Name) > 0) { return(new OperationResult(OperationResultType.ValidError, "已存在此名称的传感器!")); } } db.Entry(sensorCore).CurrentValues.SetValues(sensor); db.SaveChanges(); return(new OperationResult(OperationResultType.Success)); } catch (Exception err) { return(new OperationResult(OperationResultType.Error, err.Message)); } }