public ResponseData DeleteDeviceBaseData(DeviceBaseDataViewModel dbdvm) { ResponseData rd = new ResponseData(); //获取设备信息 DeviceModel dm = new DeviceService().FindDevice(dbdvm.DeviceSn, dbdvm.Token); if (dm == null) { rd.Success = false; rd.Message = "设备不存在"; return(rd); } #region 验证用户权限 bool bRet = new DeviceService().CheckDeviceAuth(dm, dbdvm.Account, dbdvm.Token, 2); if (!bRet) { rd.Success = false; rd.Message = "用户没有权限删除设备信息"; return(rd); } #endregion DeviceBaseDataModel dbdm = _dbdr.Find(dbdvm.Id); try { _dbdr.Remove(dbdm); rd.Message = "删除设备信息成功"; rd.Success = true; } catch (Exception) { rd.Success = false; rd.Message = "删除设备信息失败"; } return(rd); }
public void Save(DeviceBaseDataModel entity) { using (var db = new HXContext()) { db.Entry <DeviceBaseDataModel>(entity).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } }
public void Add(DeviceBaseDataModel entity) { using (var db = new HXContext()) { db.DeviceBaseData.Add(entity); db.SaveChanges(); } }
public DeviceBaseDataViewModel DeviceBaseDataAdd(DeviceBaseDataViewModel dvm) { //验证用户是否有编辑的权限,验证该条数据是否已经被添加过,添加数据 DeviceModel dm = new DeviceRepository().FindDeviceAndBaseData(dvm.DeviceSn, dvm.Token); if (dm == null) { dvm.Success = false; dvm.Message = "不存在关联的设备"; return(dvm); } #region 验证用户权限 int projectId = dm.ProjectId.Value; bool bRet = new UserService().IsAuthProject(dvm.Account, dvm.Token, projectId, 1); if (!bRet) { dvm.Success = false; dvm.Message = "该用户无添加设备的权限"; return(dvm); } #endregion DeviceBaseDataModel ddm = dm.DeviceBaseData.Where(a => a.DataName == dvm.DataName).FirstOrDefault(); if (ddm != null) { dvm.Success = false; dvm.Message = "已存在此数据"; return(dvm); } try { ddm = new DeviceBaseDataModel(); ddm.DataName = dvm.DataName; ddm.DataType = dvm.DataType; ddm.DataValue = dvm.DataValue; ddm.PanelId = dvm.PanelId; ddm.DeviceSn = dm.DeviceSn; _dbdr.Add(ddm); dvm.Id = ddm.Id; dvm.Success = true; dvm.Message = "添加数据栏位成功"; } catch (Exception ex) { dvm.Success = false; dvm.Message = "添加数据栏位失败" + ex.Message; } return(dvm); }