//[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");
        }
        public EditViewModel Edit(EditInputModel inputModel)
        {
            PerformanceMonitorRecord recordToEdit = _performanceMonitorDataService.PerformanceMonitorRecords.FirstOrDefault(r => r.Id == inputModel.Id);
            if (recordToEdit != null)
            {
                //edit an existing record (no implementation in current version)
            }

            //No existing record in the database with the given id, create a new one
            if (recordToEdit == null)
            {
                recordToEdit = new PerformanceMonitorRecord();

                recordToEdit.Id = 0;
                recordToEdit.CategoryName = inputModel.CategoryName;
                if (inputModel.InstanceName != null)
                {
                    recordToEdit.InstanceName = inputModel.InstanceName;
                }

                recordToEdit.CounterName = inputModel.CounterName;

                if (inputModel.SampleInterval <= 0)
                {
                    recordToEdit.SampleInterval = 1;
                }
                else
                {
                    recordToEdit.SampleInterval = inputModel.SampleInterval;
                }

                if (inputModel.Duration == null || Int32.Parse(inputModel.Duration) <= 0)
                {
                    recordToEdit.Duration = "1";
                }
                else
                {
                    recordToEdit.Duration = inputModel.Duration;
                }
                recordToEdit.Threshold = 0;
                //ThresholdWhen default value is 'Above'
                recordToEdit.ThresholdWhen = false;
            }

            string myCatName = inputModel.CategoryName;
            List<string> performanceCounters;
            if (inputModel.InstanceName == "none")
            {
                performanceCounters = _performanceMonitorService.GetCounterNames(myCatName, null);
            }
            else
            {
                string myInstanceName = inputModel.InstanceName;
                performanceCounters = _performanceMonitorService.GetCounterNames(myCatName,myInstanceName);
            }

            var counterList = performanceCounters.Select(c => new SelectListItem
            {
                Text = c.ToString(),
                Value = c.ToString()
            });


            Dictionary<string, string> thresholdWhenValues = new Dictionary<string, string>();
            thresholdWhenValues.Add("false", "Above");
            thresholdWhenValues.Add("true", "Below");

            var thresholdWhenList = thresholdWhenValues.Select(c => new SelectListItem
            {
                Value = c.Key,
                Text = c.Value
            });

            EditViewModel viewModel = new EditViewModel()
            {
                Id = recordToEdit.Id,
                CategoryName = inputModel.CategoryName,
                CounterList = new SelectList(counterList, "Value", "Text", recordToEdit.CounterName),
                ThresholdWhenList = new SelectList(thresholdWhenList, "Value", "Text",recordToEdit.ThresholdWhen),
                Duration = recordToEdit.Duration,
                SampleInterval = recordToEdit.SampleInterval
            };

            return viewModel;
        }
        //[HandleError, OrchardAuthorization(PermissionName = ApplicationFrameworkPermissionStrings.EditConfigurationSettings)]
        public ActionResult Edit(string selectedCategoryName, string selectedInstanceName)
        {
            EditInputModel inputModel = new EditInputModel();

            inputModel.CategoryName = selectedCategoryName;
            inputModel.InstanceName = selectedInstanceName.ToString();
            EditViewModel viewModel = _performanceMonitorWorkerService.Edit(inputModel);
            viewModel.InstanceName = selectedInstanceName.ToString();

            return View(viewModel);
        }