public ActionResult Fence(FenceAlert alertModel) { { ScheduleViewModel sVM = new ScheduleViewModel(); //sVM.SelectedAlertType = DeviceAlarmType.FenceAlarm; sVM.SelectedAlertType = alertModel.FenceType; sVM.AlertDatas = new List <object>(); AlertBase alertData = new AlertBase() { Id = alertModel.Id, Name = alertModel.Name, DescriptionText = alertModel.Description, IsActive = alertModel.IsActive, FenceListStr = alertModel.PointsStr }; sVM.AlertDatas.Add(alertData); if (new AlertData().SaveAlertData(sVM)) { int updateId = 0; if (int.TryParse(sVM.SelectedAlertId, out updateId)) { alertModel.Id = updateId; try { alertModel.Points = (sVM.AlertDatas[0] as AlertBase).FenceList; } catch (Exception aBEx) { } if (alertModel.Devices != null && alertModel.Devices.Count > 0) { alertModel.Devices.ForEach(d => { try { new AlertData().SaveDevicesForAlert(alertModel.Id, d.DeviceId, !d.Checked); } catch (Exception ex) { } }); } } ViewBag.AlertWriteStatus = "Success"; } else { ViewBag.AlertWriteStatus = "Failed"; } return(View(alertModel)); } }
public ActionResult Fence(int Id = 0) { FenceAlert alertModel = new FenceAlert(); try { ScheduleViewModel sVM = new ScheduleViewModel(); sVM.SelectedAlertType = DeviceAlarmType.FenceAlarm; sVM = new AlertData().GetAlertDetails(sVM, Id); AlertBase alertData = sVM.AlertDatas.FirstOrDefault() as AlertBase; if (alertData == null) { alertData = new AlertBase() { Id = 0, Conditions = new List <Tracker.Common.Condition>(), IsActive = false }; } alertModel = new FenceAlert() { Id = alertData.Id, Name = alertData.Name, Description = alertData.DescriptionText, IsActive = alertData.IsActive, FenceType = (Id == 0) ? DeviceAlarmType.FenceInAlarm : sVM.SelectedAlertType, Points = alertData.FenceList, Devices = new List <DeviceDetailSelection>() }; List <DeviceDetailSelection> availableDevices = new AlertData().GetAvailableDevices(); List <string> activeDevices = new AlertData().GetDevicesForAlert(alertData.Id); if (availableDevices != null && availableDevices.Count > 0) { alertModel.Devices = availableDevices.Select(m => new DeviceDetailSelection { DeviceId = m.DeviceId, VehicleId = m.VehicleId, Checked = activeDevices.Contains(m.DeviceId) }).ToList(); } } catch (Exception ex) { } return(View(alertModel)); }