Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        public ActionResult PowerCut(PowerCutAlert alertModel)
        {
            ScheduleViewModel sVM = new ScheduleViewModel();

            sVM.SelectedAlertType = DeviceAlarmType.PowerCutAlarm;

            sVM.AlertDatas = new List <object>();
            AlertBase alertData = new AlertBase()
            {
                Id         = alertModel.Id,
                IsActive   = alertModel.IsActive,
                Conditions = new List <Tracker.Common.Condition>()
                {
                    new Tracker.Common.Condition()
                    {
                        Operand = "OnPowerCut",
                        Value   = alertModel.IsOnPowerCut == true ? "1" : "0"
                    }
                }
            };

            sVM.AlertDatas.Add(alertData);

            if (new AlertData().SaveAlertData(sVM))
            {
                int updateId = 0;
                if (int.TryParse(sVM.SelectedAlertId, out updateId))
                {
                    alertModel.Id = updateId;
                    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));
        }