Beispiel #1
0
 public void Add(DeviceOnlineModel entity)
 {
     using (var db = new HXContext())
     {
         db.DeviceOnline.Add(entity);
         db.SaveChanges();
     }
 }
Beispiel #2
0
 public void Save(DeviceOnlineModel entity)
 {
     using (var db = new HXContext())
     {
         db.Entry <DeviceOnlineModel>(entity).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
Beispiel #3
0
        //处理设备在线数据上传信息
        public DeviceOnlineViewModel DeviceOnlineAdd(DeviceOnlineViewModel dovm)
        {
            //检测设备和组织是否存在,如果不存在则对数据不做处理
            DeviceModel dm = new DeviceRepository().FindDeviceAndDeviceOnline(dovm.DeviceSn, dovm.Token);

            if (dm == null)
            {
                dovm.Success = false;
                dovm.Message = "不存在此设备或者组织";
                return(dovm);
            }
            try
            {
                //如果不存在此设备的数据,则添加设备数据,不存在则修改数据
                DeviceOnlineModel dom = new DeviceOnlineModel()
                {
                    DataContent = dovm.DataContent, DataTitle = dovm.DataContent, dt = DateTime.Now, DeviceSn = dm.DeviceSn, Token = dovm.Token
                };
                if (dm.DeviceOnline == null)
                {
                    _dor.Add(dom);
                }
                else
                {
                    _dor.Save(dom);
                }
            }
            catch (Exception ex)
            {
                dovm.Success = false;
                dovm.Message = "添加设备在线数据失败" + ex.Message;
                return(dovm);
            }
            dovm.Success = true;
            dovm.Message = "添加设备在线数据成功";
            return(dovm);
        }