public EditViewModel(EditPostInputModel inputModel)
 {
     Id = inputModel.Id;
     CategoryName = inputModel.CategoryName;
     InstanceName = inputModel.InstanceName;
     CounterName = inputModel.CounterName;
     Duration = inputModel.Duration;
     SampleInterval = inputModel.SampleInterval;
     Threshold = inputModel.Threshold;
     ThresholdWhen = inputModel.ThresholdWhen;
 }
        public bool EditPost(EditPostInputModel inputModel)
        {
            string performanceCounterReading =
                _performanceCounterService.GetPerformanceCounterReading(inputModel.CategoryName,inputModel.InstanceName,inputModel.CounterName);

            if (performanceCounterReading == String.Empty)
            {
                _notifier.Error(T("Error: Not able to perform a reading on this type of counter"));
                return false;
            }

            PerformanceMonitorRecord record = new PerformanceMonitorRecord()
            {
                Id = inputModel.Id,
                CategoryName = inputModel.CategoryName,
                InstanceName = inputModel.InstanceName,
                CounterName = inputModel.CounterName,
                InitialValue = performanceCounterReading,
                Duration = inputModel.Duration,
                SampleInterval = inputModel.SampleInterval,
                Threshold = inputModel.Threshold,
                ThresholdWhen = inputModel.ThresholdWhen
            };

            var result = _performanceMonitorDataService.SetPerformanceMonitorRecord(record);
            if (result)
            {
                PerformanceMonitorRecord activeRecord =
                    _performanceMonitorDataService.PerformanceMonitorRecords.FirstOrDefault(r => r.IsEnabled == true);

                //threshold check
                bool passedThreshold;
                var passedThresholdValue = 0;
                double countervalue = double.Parse(activeRecord.InitialValue);

                passedThreshold = _performanceMonitorService.CheckThreshold(activeRecord.Threshold, activeRecord.ThresholdWhen, countervalue, ref passedThresholdValue);

                PerformanceMonitorDataRecord datarecord = new PerformanceMonitorDataRecord() 
                {
                    PerformanceMonitorRecord_Id = activeRecord.Id,
                    Count = activeRecord.InitialValue,
                    HeartBeat = activeRecord.Created,
                    PassedThreshold = passedThreshold,
                    PassedThresholdValue = passedThresholdValue,

                    //duration count(ticks in nanoseconds from starttime (created)) should initially be set to startvalue (zero)
                    Ticks = "0"
                };

                var dataResult = _performanceMonitorDataService.WriteDataRecord(datarecord);
                if (dataResult)
                {
                    _notifier.Information(T("New counter records added succesfully"));
                }
                else
                {
                    _notifier.Warning(T("New counter record added succesfully, but failed to write initial datarecord"));
                }
            }
            else
            {
                _notifier.Error(T("Error: Failed to add new counter"));
            }
            return result;
        }
        //[HandleError, OrchardAuthorization(PermissionName = ApplicationFrameworkPermissionStrings.EditConfigurationSettings)]
        public ActionResult EditPost(EditPostInputModel inputModel)
        {
            EditInputModel newEditInputModel = new EditInputModel()
            {
                Id = inputModel.Id,
                CategoryName = inputModel.CategoryName,
                InstanceName = inputModel.InstanceName,
                CounterName = inputModel.CounterName,
                Duration = inputModel.Duration,
                SampleInterval = inputModel.SampleInterval
            };

            if (!ModelState.IsValid)
            {
                EditViewModel viewModel = _performanceMonitorWorkerService.Edit(newEditInputModel);
                return View("Edit", viewModel);
            }

            _performanceMonitorWorkerService.EditPost(inputModel);

            return RedirectToAction("Index");
        }