Пример #1
0
        /// <summary>
        /// 移除报警设置
        /// </summary>
        /// <param name="db"></param>
        /// <param name="alarmSourceIds"></param>
        public static void RemoveAlarmSetting(AllInOneContext.AllInOneContext db, List <Guid> alarmSourceIds)
        {
            //删除报警配置
            var alarmsettings = db.AlarmSetting.Where(t => alarmSourceIds.Contains(t.AlarmSourceId)).ToList();

            if (alarmsettings != null && alarmsettings.Count > 0)
            {
                List <Guid> removePlanIds     = new List <Guid>();
                List <Guid> removeScheduleIds = new List <Guid>();
                alarmsettings.ForEach(t =>
                {
                    if (t.BeforePlanId != null)
                    {
                        removePlanIds.Add(t.BeforePlanId.Value);
                    }
                    if (t.EmergencyPlanId != null)
                    {
                        removePlanIds.Add(t.EmergencyPlanId.Value);
                    }
                    removeScheduleIds.Add(t.ScheduleId);
                });
                db.AlarmSetting.RemoveRange(alarmsettings);
                AlarmSettingUtility.RemoveAlarmSettingPlan(db, removePlanIds);
                AlarmSettingUtility.RemoveAlarmSettingSchedule(db, removeScheduleIds);
                db.SaveChanges();
            }
        }
Пример #2
0
 public IActionResult Remove(Guid id)
 {
     using (var db = new AllInOneContext.AllInOneContext())
     {
         using (var transaction = db.Database.BeginTransaction())
         {
             try
             {
                 MonitorySite ms = db.MonitorySite.FirstOrDefault(t => t.MonitorySiteId.Equals(id));
                 if (ms == null)
                 {
                     return(NotFound());
                 }
                 Camera       camera       = db.Set <Camera>().First(t => t.CameraId.Equals(ms.CameraId));
                 IPDeviceInfo cameraDevice = db.IPDeviceInfo.First(t => t.IPDeviceInfoId.Equals(camera.IPDeviceId));
                 db.MonitorySite.Remove(ms);
                 db.Set <Camera>().Remove(camera);
                 //db.IPDeviceInfo.Remove(cameraDevice);
                 var deleteStatusId = Guid.Parse("a0002016-e009-b019-e001-abcd13800005");
                 cameraDevice.StatusId = deleteStatusId;
                 //Remove AlarmSetting
                 List <Guid> alarmSourceIds = new List <Guid>();
                 alarmSourceIds.Add(cameraDevice.IPDeviceInfoId);
                 AlarmSettingUtility.RemoveAlarmSetting(db, alarmSourceIds);
                 db.SaveChanges();
                 transaction.Commit();
                 //推送到dcp,数据同步。。。。。。
                 return(new NoContentResult());
             }
             catch (DbUpdateException dbEx)
             {
                 transaction.Rollback();
                 _logger.LogError("删除监控点异常:Message:{0}\r\n,StackTrace:{1}", dbEx.Message, dbEx.StackTrace);
                 return(BadRequest(new ApplicationException {
                     ErrorCode = "DBUpdate", ErrorMessage = "数据保存异常:" + dbEx.Message
                 }));
             }
             catch (Exception ex)
             {
                 _logger.LogError("删除监控点异常:Message:{0}\r\n,StackTrace:{1}", ex.Message, ex.StackTrace);
                 return(BadRequest(new ApplicationException {
                     ErrorCode = "Unknown", ErrorMessage = ex.Message
                 }));
             }
         }
     }
 }
Пример #3
0
        public IActionResult Delete(Guid id)
        {
            using (var db = new AllInOneContext.AllInOneContext())
            {
                using (var tran = db.Database.BeginTransaction())
                {
                    try
                    {
                        Sentinel deleteObj = GetQuery(db).FirstOrDefault(t => t.SentinelId.Equals(id));
                        if (deleteObj == null)
                        {
                            return(NotFound());
                        }
                        //if (deleteObj.BulletboxCamera != null)
                        //    db.Set<SentinelVideo>().Remove(deleteObj.BulletboxCamera);
                        //if (deleteObj.FrontCamera != null)
                        //    db.Set<SentinelVideo>().Remove(deleteObj.FrontCamera);
                        //if (deleteObj.SentinelVideos != null)
                        //    db.Set<SentinelVideo>().RemoveRange(deleteObj.SentinelVideos);
                        //if (deleteObj.DeviceInfo != null)
                        //    db.IPDeviceInfo.Remove(deleteObj.DeviceInfo);
                        //if (deleteObj.SentinelSetting != null)
                        //    db.Set<SentinelSetting>().Remove(deleteObj.SentinelSetting);
                        //if (deleteObj.DefenseDevices != null)
                        //    db.DefenseDevice.RemoveRange(deleteObj.DefenseDevices);
                        //if (deleteObj.AlarmOutputChannels != null)
                        //    db.Set<DeviceChannelSetting>().RemoveRange(deleteObj.AlarmOutputChannels);
                        //移除哨位台人员指纹
                        DeleteSentinelFingerInfo(db, deleteObj);
                        //db.Sentinel.Remove(deleteObj);
                        //将设备标记为移除状态
                        var deleteStatusId = Guid.Parse("a0002016-e009-b019-e001-abcd13800005");
                        deleteObj.DeviceInfo.StatusId = deleteStatusId;

                        //报警配置设备id
                        List <Guid> alarmSourceIds = new List <Guid>();

                        if (deleteObj.DefenseDevices != null)
                        {
                            deleteObj.DefenseDevices.ForEach(t =>
                            {
                                t.DeviceInfo.StatusId = deleteStatusId;
                                alarmSourceIds.Add(t.DeviceInfoId);
                            });
                        }
                        db.IPDeviceInfo.Update(deleteObj.DeviceInfo);
                        db.IPDeviceInfo.UpdateRange(deleteObj.DefenseDevices.Select(t => t.DeviceInfo));
                        db.SaveChanges();

                        alarmSourceIds.Add(deleteObj.DeviceInfoId);
                        //删除报警配置
                        AlarmSettingUtility.RemoveAlarmSetting(db, alarmSourceIds);

                        tran.Commit();
                        SendDatachangeNotify(deleteObj.DeviceInfo, 0);
                    }
                    catch (DbUpdateException dbEx)
                    {
                        tran.Rollback();
                        _logger.LogError("删除哨位台异常:Message:{0}\r\n,StackTrace:{1}", dbEx.Message, dbEx.StackTrace);
                        return(BadRequest(new ApplicationException {
                            ErrorCode = "DBUpdate", ErrorMessage = "数据保存异常:" + dbEx.Message
                        }));
                    }
                    catch (Exception ex)
                    {
                        tran.Rollback();
                        _logger.LogError("删除哨位台异常:Message:{0}\r\n,StackTrace:{1}", ex.Message, ex.StackTrace);
                        return(BadRequest(new ApplicationException {
                            ErrorCode = "Unknown", ErrorMessage = ex.Message
                        }));
                    }
                }
            }
            return(NoContent());
        }