public ActionResult Speed(int Id = 0) { SpeedAlert alertModel = new SpeedAlert(); try { ScheduleViewModel sVM = new ScheduleViewModel(); sVM.SelectedAlertType = DeviceAlarmType.SpeedAlarm; 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 }; } int SpeedLimit = 50; string SpeedComparer = string.Empty; if (alertData.Conditions.Where(m => m.Operand == "Speed").FirstOrDefault() != null) { SpeedLimit = Convert.ToInt32(alertData.Conditions.Where(m => m.Operand == "Speed").FirstOrDefault().Value); SpeedComparer = Convert.ToString(alertData.Conditions.Where(m => m.Operand == "Speed").FirstOrDefault().Operator); } alertModel = new SpeedAlert() { Id = alertData.Id, Name = alertData.Name, Description = alertData.DescriptionText, IsActive = alertData.IsActive, SpeedLimit = SpeedLimit, SpeedComparer = SpeedComparer, 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)); }
public ActionResult PowerCut(int?Id = null) { PowerCutAlert alertModel = new PowerCutAlert(); try { ScheduleViewModel sVM = new ScheduleViewModel(); sVM.SelectedAlertType = DeviceAlarmType.PowerCutAlarm; 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 }; } bool IsOnPowerCut = false; if (alertData.Conditions.Where(m => m.Operand == "OnPowerCut").FirstOrDefault() != null) { IsOnPowerCut = Convert.ToBoolean(Convert.ToInt32(alertData.Conditions.Where(m => m.Operand == "OnPowerCut").FirstOrDefault().Value)); } else { IsOnPowerCut = false; } alertModel = new PowerCutAlert() { Id = alertData.Id, IsActive = alertData.IsActive, IsOnPowerCut = IsOnPowerCut, 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(); } // TODO: Get from db/old service } catch (Exception ex) { } 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)); }